1 #include "wrt/src/browser/api/wrt_api_web_contents.h"
3 #include <Elementary.h>
5 #include "base/functional/bind.h"
6 #include "content/browser/renderer_host/edge_effect.h"
7 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
8 #include "electron/shell/common/node_includes.h"
9 #include "tizen_src/chromium_impl/tizen/system_info.h"
10 #include "tizen_src/chromium_impl/ui/ozone/platform/efl/im_context_efl.h"
11 #include "tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.h"
12 #include "wrt/src/browser/wrt_input_picker.h"
13 #include "wrt/src/browser/wrt_javascript_dialog_manager.h"
14 #include "wrt/src/browser/wrt_native_window.h"
15 #include "wrt/src/browser/wrt_web_contents.h"
16 #include "wrt/src/common/application_data.h"
18 #if BUILDFLAG(IS_TIZEN_TV)
19 #include "wrt/src/browser/tv/native_web_runtime_delegate_tv.h"
20 #include "wrt/src/browser/tv/popup_tv.h"
27 WebContents::WebContents(
28 v8::Isolate* isolate, const gin_helper::Dictionary& options)
29 : electron::api::WebContents(isolate, options) {}
31 WebContents::WebContents(v8::Isolate* isolate,
32 std::unique_ptr<content::WebContents> web_contents,
34 : electron::api::WebContents(isolate, std::move(web_contents), type) {}
36 WebContents::~WebContents() {}
38 void WebContents::NavigationStateChanged(
39 content::WebContents* source, content::InvalidateTypes changed_flags) {
40 if (changed_flags & content::INVALIDATE_TYPE_URL) {
41 auto* wrt_wc = WRTWebContents::FromWebContents(web_contents());
43 wrt_wc->ResetControllers();
47 bool WebContents::DidAddMessageToConsole(
48 content::WebContents* source,
49 blink::mojom::ConsoleMessageLevel level,
50 const std::u16string& message,
52 const std::u16string& source_id) {
53 #if BUILDFLAG(IS_TIZEN_TV)
56 return Emit("console-message", static_cast<int32_t>(level), message, line_no,
61 bool WebContents::HandleContextMenu(
62 content::RenderFrameHost& render_frame_host,
63 const content::ContextMenuParams& params) {
64 auto& app_data = ApplicationData::GetInstance();
65 return !app_data.setting_info().context_menu_enabled();
68 content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
69 content::WebContents* source) {
71 dialog_manager_ = std::make_unique<WRTJavaScriptDialogManager>();
73 return dialog_manager_.get();
76 std::unique_ptr<content::ColorChooser> WebContents::OpenColorChooser(
77 content::WebContents* web_contents,
79 const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions) {
80 auto* color_chooser_efl = new content::ColorChooserEfl(*web_contents);
81 auto* evas_object = WRTNativeWindow::GetTopWindow();
82 wrt_input_picker_.reset(new WRTInputPicker(GetWebContents(), evas_object));
83 wrt_input_picker_->ShowColorPicker(SkColorGetR(color), SkColorGetG(color),
84 SkColorGetB(color), SkColorGetA(color));
85 return std::unique_ptr<content::ColorChooserEfl>(color_chooser_efl);
88 void WebContents::WillDraw(int new_rotation, gfx::Size frame_data_output_size) {
89 #if !BUILDFLAG(IS_TIZEN_TV)
90 if (!IsMobileProfile())
94 const bool is_manual_rotation_not_initialized =
95 (rotation_ == -1) && (frame_output_size_.width() == 0);
96 const bool is_changed_landscape_to_landscape =
97 (rotation_ == 90 && new_rotation == 270) ||
98 (rotation_ == 270 && new_rotation == 90);
99 const bool is_changed_portrait_to_portrait =
100 (rotation_ == 0 && new_rotation == 180) ||
101 (rotation_ == 180 && new_rotation == 0);
102 const bool is_frame_data_width_changed =
103 frame_output_size_.width() != frame_data_output_size.width();
104 // While javascript dialog(alert, etc.) is showing, renderer is blocked.
105 // As a result, rotated frame is not rendered although device is rotated
106 // when javascript dialog is showing.
107 auto* dialog_manager = static_cast<WRTJavaScriptDialogManager*>(
108 GetJavaScriptDialogManager(GetWebContents()));
109 const bool is_showing_javascript_dialog = dialog_manager &&
110 dialog_manager->IsShowing() &&
111 rotation_ != new_rotation;
112 if (is_manual_rotation_not_initialized || is_changed_landscape_to_landscape ||
113 is_changed_portrait_to_portrait || is_frame_data_width_changed ||
114 is_showing_javascript_dialog) {
115 rotation_ = new_rotation;
116 frame_output_size_.set_width(frame_data_output_size.width());
117 auto* ee = WRTNativeWindow::GetPlatformCanvas();
118 if (EINA_TRUE == ecore_evas_wm_rotation_manual_rotation_done_get(ee)) {
119 LOG(INFO) << "finalize window rotation done";
120 ecore_evas_wm_rotation_manual_rotation_done(ee);
124 #if BUILDFLAG(IS_TIZEN_TV)
125 if (frame_output_size_.height() != frame_output_size_.height()) {
126 #if !defined(WRT_JS_BRINGUP)
127 auto rwhva = static_cast<content::RenderWidgetHostViewAura*>(
128 GetWebContents()->GetRenderWidgetHostView());
129 if (rwhva && rwhva->aura_efl_helper() &&
130 rwhva->aura_efl_helper()->GetIMContextEfl()) {
131 rwhva->aura_efl_helper()->GetIMContextEfl()->RequestHide();
135 frame_output_size_.set_height(frame_output_size_.height());
139 #if BUILDFLAG(IS_TIZEN_TV)
140 void WebContents::ShowMicOpenedNotification(bool show) {
143 NativeWebRuntimeDelegateTV::GetInstance().GetAppTitleForPcm();
144 if (!pcm_title.empty()) {
145 PopupTV::ShowVoiceRecognitionToast(pcm_title);
148 PopupTV::HideVoiceRecognitionToast();
153 void WebContents::DidReceiveNonEmtpyLayoutFrame() {
157 void WebContents::DidFirstVisuallyNonEmptyPaint() {
161 void WebContents::WebContentsDestroyed() {
163 dialog_manager_.reset();
165 electron::api::WebContents::WebContentsDestroyed();
168 void WebContents::EmitReadyToShow() {
169 auto* window = WRTNativeWindow::FromWebContents(GetWebContents());
170 if (!window->IsClosed() && !window->IsVisible())
171 Emit("ready-to-show");
182 gin::Handle<WebContents> WebContents::New(
183 v8::Isolate* isolate,
184 const gin_helper::Dictionary& options) {
185 WebContents* api_web_contents =
186 new wrt::api::WebContents(isolate, options);
187 gin::Handle<WebContents> handle =
188 gin::CreateHandle(isolate, api_web_contents);
189 v8::TryCatch try_catch(isolate);
190 gin_helper::CallMethod(isolate, handle.get(), "_init");
191 if (try_catch.HasCaught()) {
192 node::errors::TriggerUncaughtException(isolate, try_catch);
198 gin::Handle<WebContents> WebContents::CreateAndTake(
199 v8::Isolate* isolate,
200 std::unique_ptr<content::WebContents> web_contents,
202 WebContents* api_web_contents =
203 new wrt::api::WebContents(isolate, std::move(web_contents), type);
204 gin::Handle<WebContents> handle =
205 gin::CreateHandle(isolate, api_web_contents);
206 v8::TryCatch try_catch(isolate);
207 gin_helper::CallMethod(isolate, handle.get(), "_init");
208 if (try_catch.HasCaught()) {
209 node::errors::TriggerUncaughtException(isolate, try_catch);
215 } // namespace electron