Improves MCD Score from 2.08 to 3.33.
Reduces LOC for WebContentsDelegateEfl by ~280 lines.
Reduces LOC for ContentBrowserClientEfl by ~85 lines.
References:
https://review.tizen.org/gerrit/275891
https://review.tizen.org/gerrit/275576
https://review.tizen.org/gerrit/275660
https://review.tizen.org/gerrit/276084
Change-Id: Ic034b902c7ccf9d74c100641aadbf604763c5f95
Signed-off-by: Gajendra N <gajendra.n@samsung.com>
sources = [
"authentication_challenge_popup.cc",
"authentication_challenge_popup.h",
- "autofill_popup_view_efl.cc",
- "autofill_popup_view_efl.h",
+ "browser/autofill_popup_view_efl.cc",
+ "browser/autofill_popup_view_efl.h",
"browser/background_sync_controller_efl.cc",
"browser/background_sync_controller_efl.h",
"browser/browsing_data_remover_efl.cc",
"browser/browsing_data_remover_efl.h",
- "browser/download_manager_delegate_efl.cc",
- "browser/download_manager_delegate_efl.h",
"browser/intercept_request_params.h",
"browser/javascript_dialog_manager_efl.cc",
"browser/javascript_dialog_manager_efl.h",
"browser/javascript_modal_dialog_efl.cc",
"browser/javascript_modal_dialog_efl.h",
- "browser/login_delegate_efl.cc",
- "browser/login_delegate_efl.h",
"browser/mime_override_manager_efl.cc",
"browser/mime_override_manager_efl.h",
"browser/navigation_policy_handler_efl.cc",
"devtools_delegate_efl.h",
"devtools_manager_delegate_efl.cc",
"devtools_manager_delegate_efl.h",
+ "download_manager_delegate_efl.cc",
+ "download_manager_delegate_efl.h",
"efl_webprocess_main.cc",
"efl_webprocess_main.h",
"eweb_context.cc",
"http_user_agent_settings_efl.h",
"locale_efl.cc",
"locale_efl.h",
+ "login_delegate_efl.cc",
+ "login_delegate_efl.h",
"network_delegate_efl.cc",
"network_delegate_efl.h",
"notification_permission_popup.cc",
"renderer/render_thread_observer_efl.h",
"renderer/tizen_extensible.cc",
"renderer/tizen_extensible.h",
+ "web_contents_observer_efl.cc",
+ "web_contents_observer_efl.h",
"wrt/dynamicplugin.cc",
"wrt/dynamicplugin.h",
"wrt/v8widget.cc",
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
+#include "browser_context_efl.h"
#include "common/web_contents_utils.h"
#include "content/common/paths_efl.h"
#include "content/public/browser/browser_thread.h"
#include "browser/mime_override_manager_efl.h"
#include "browser/network_service/browser_url_loader_throttle_efl.h"
#include "browser/policy_response_params.h"
+#include "browser_context_efl.h"
#include "common/web_contents_utils.h"
#include "content/public/browser/render_frame_host.h"
#include "eweb_view.h"
#include "private/ewk_policy_decision_private.h"
#include "services/network/public/cpp/data_element.h"
#include "services/network/public/cpp/features.h"
-#include "services/network/public/mojom/url_response_head.mojom-forward.h"
+#include "services/network/public/mojom/url_response_head.mojom.h"
using web_contents_utils::WebViewFromWebContents;
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "eweb_view.h"
#include "ipc_message_start_ewk.h"
#include "base/files/scoped_temp_dir.h"
#include "base/synchronization/lock.h"
-#include "browser/download_manager_delegate_efl.h"
#include "browser/geolocation/geolocation_permission_context_efl.h"
#include "browser/ssl_host_state_delegate_efl.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
+#include "download_manager_delegate_efl.h"
#include "url_request_context_getter_efl.h"
class CookieManager;
#include "browser/quota_permission_context_efl.h"
#include "browser/render_message_filter_efl.h"
#include "browser/web_view_browser_message_filter.h"
+#include "browser_context_efl.h"
#include "browser_main_parts_efl.h"
#include "command_line_efl.h"
#include "common/content_switches_efl.h"
#include "components/error_page/common/localized_error.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/browser/web_contents.h"
}
#endif // BUILDFLAG(IS_TIZEN)
-} // namespace
-
-ContentBrowserClientEfl::ContentBrowserClientEfl()
- : browser_main_parts_efl_(nullptr),
- notification_controller_(new NotificationControllerEfl),
- accept_langs_(kDefaultAcceptLanguages) {
-#if BUILDFLAG(IS_TIZEN)
- PlatformLanguageChanged(nullptr, this);
- vconf_notify_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged, this);
-#endif
-}
-
-ContentBrowserClientEfl::~ContentBrowserClientEfl() {
-#if BUILDFLAG(IS_TIZEN)
- vconf_ignore_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged);
-#endif
-}
-
-void ContentBrowserClientEfl::SetBrowserContext(BrowserContext* context) {
- browser_context_.reset(context);
-}
-
-void ContentBrowserClientEfl::CleanUpBrowserContext() {
- browser_context_.reset(nullptr);
- shutting_down_ = true;
-}
-
-std::unique_ptr<BrowserMainParts>
-ContentBrowserClientEfl::CreateBrowserMainParts(bool is_integration_test) {
- auto browser_main_parts = std::make_unique<BrowserMainPartsEfl>();
- browser_main_parts_efl_ = browser_main_parts.get();
- return browser_main_parts;
-}
-
-void ContentBrowserClientEfl::AppendExtraCommandLineSwitchesInternal(
- base::CommandLine* command_line,
- int child_process_id) {
+void AppendExtraCommandLineSwitchesInternal(base::CommandLine* command_line,
+ int child_process_id) {
if (!command_line->HasSwitch(switches::kProcessType))
return;
widget_encoded_bundle);
}
+void DispatchPopupBlockedOnUIThread(int render_process_id,
+ const GURL& target_url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ std::unique_ptr<RenderWidgetHostIterator> widgets(
+ RenderWidgetHost::GetRenderWidgetHosts());
+ RenderWidgetHost* widget = NULL;
+
+ while ((widget = widgets->GetNextHost()))
+ if (widget->GetProcess()->GetID() == render_process_id)
+ break;
+
+ // It may happen that this message will be handled on ui thread after view
+ // was closed. In such case ignore do nothing.
+ if (!widget)
+ return;
+ RenderViewHost* vh = RenderViewHost::From(widget);
+ if (!vh)
+ return;
+
+ WebContents* content = WebContents::FromRenderViewHost(vh);
+ if (!content)
+ return;
+
+ EWebView* wv = WebViewFromWebContents(content);
+ wv->SmartCallback<EWebViewCallbacks::PopupBlocked>().call(
+ target_url.spec().c_str());
+}
+
+} // namespace
+
+AcceptLanguagesHelper::AcceptLanguagesHelper()
+ : accept_langs_(kDefaultAcceptLanguages) {}
+
+AcceptLanguagesHelper::~AcceptLanguagesHelper() {}
+
+std::string AcceptLanguagesHelper::GetAcceptLangs() {
+ if (!preferred_langs_.empty())
+ return preferred_langs_;
+
+ return accept_langs_;
+}
+
+void AcceptLanguagesHelper::SetAcceptLangs(const std::string& accept_langs) {
+ if (accept_langs.empty() || accept_langs_ == accept_langs)
+ return;
+
+ accept_langs_ = accept_langs;
+ if (preferred_langs_.empty())
+ NotifyAcceptLangsChanged();
+}
+
+void AcceptLanguagesHelper::SetPreferredLangs(
+ const std::string& preferred_langs) {
+ if (preferred_langs_ == preferred_langs)
+ return;
+
+ preferred_langs_ = preferred_langs;
+ NotifyAcceptLangsChanged();
+}
+
+void AcceptLanguagesHelper::AddAcceptLangsChangedCallback(
+ AcceptLangsChangedCallback callback) {
+ if (callback)
+ accept_langs_changed_callbacks_.push_back(std::move(callback));
+}
+
+void AcceptLanguagesHelper::RemoveAcceptLangsChangedCallback(
+ AcceptLangsChangedCallback callback) {
+#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
+ for (size_t i = 0; i < accept_langs_changed_callbacks_.size(); ++i) {
+ if (accept_langs_changed_callbacks_[i] == callback) {
+ accept_langs_changed_callbacks_.erase(
+ accept_langs_changed_callbacks_.begin() + i);
+ return;
+ }
+ }
+#endif
+}
+
+void AcceptLanguagesHelper::NotifyAcceptLangsChanged() {
+ std::vector<AcceptLangsChangedCallback> callbacks;
+ callbacks.swap(accept_langs_changed_callbacks_);
+
+ for (auto& callback : callbacks) {
+ if (preferred_langs_.empty())
+ std::move(callback).Run(accept_langs_);
+ else
+ std::move(callback).Run(preferred_langs_);
+ }
+}
+
+ContentBrowserClientEfl::ContentBrowserClientEfl()
+ : notification_controller_(new NotificationControllerEfl),
+ accept_langs_helper_(new AcceptLanguagesHelper) {
+#if BUILDFLAG(IS_TIZEN)
+ PlatformLanguageChanged(nullptr, this);
+ vconf_notify_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged, this);
+#endif
+}
+
+ContentBrowserClientEfl::~ContentBrowserClientEfl() {
+#if BUILDFLAG(IS_TIZEN)
+ vconf_ignore_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged);
+#endif
+}
+
+void ContentBrowserClientEfl::SetBrowserContext(BrowserContext* context) {
+ browser_context_.reset(context);
+}
+
+void ContentBrowserClientEfl::CleanUpBrowserContext() {
+ browser_context_.reset(nullptr);
+ shutting_down_ = true;
+}
+
+std::unique_ptr<BrowserMainParts>
+ContentBrowserClientEfl::CreateBrowserMainParts(bool is_integration_test) {
+ auto browser_main_parts = std::make_unique<BrowserMainPartsEfl>();
+ browser_main_parts_efl_ = browser_main_parts.get();
+ return browser_main_parts;
+}
+
void ContentBrowserClientEfl::AppendExtraCommandLineSwitches(
base::CommandLine* command_line,
int child_process_id) {
#if !defined(EWK_BRINGUP) // FIXME: m67 bringup
if (!user_gesture) {
*no_javascript_access = true;
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::BindOnce(&ContentBrowserClientEfl::DispatchPopupBlockedOnUIThread,
- render_process_id, target_url));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::BindOnce(&DispatchPopupBlockedOnUIThread,
+ render_process_id, target_url));
return false;
}
#endif
return policy_decision->CanCreateWindow();
}
-void ContentBrowserClientEfl::DispatchPopupBlockedOnUIThread(
- int render_process_id,
- const GURL& target_url) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- std::unique_ptr<RenderWidgetHostIterator> widgets(
- RenderWidgetHost::GetRenderWidgetHosts());
- RenderWidgetHost* widget = NULL;
-
- while ((widget = widgets->GetNextHost()))
- if (widget->GetProcess()->GetID() == render_process_id)
- break;
-
- // It may happen that this message will be handled on ui thread after view
- // was closed. In such case ignore do nothing.
- if (!widget)
- return;
- RenderViewHost* vh = RenderViewHost::From(widget);
- if (!vh)
- return;
-
- WebContents* content = WebContents::FromRenderViewHost(vh);
- if (!content)
- return;
-
- EWebView* wv = WebViewFromWebContents(content);
- wv->SmartCallback<EWebViewCallbacks::PopupBlocked>().call(
- target_url.spec().c_str());
-}
-
bool ContentBrowserClientEfl::HasErrorPage(int http_status_code) {
// Use an internal error page, if we have one for the status code.
return error_page::LocalizedError::HasStrings(
#endif // !defined(EWK_BRINGUP)
}
-PlatformNotificationService*
-ContentBrowserClientEfl::GetPlatformNotificationService(
- BrowserContext* browser_context) {
- return notification_controller_.get();
-}
-
NotificationControllerEfl* ContentBrowserClientEfl::GetNotificationController()
const {
return notification_controller_.get();
}
std::string ContentBrowserClientEfl::GetAcceptLangs(BrowserContext* context) {
- if (!preferred_langs_.empty())
- return preferred_langs_;
-
- return accept_langs_;
+ return accept_langs_helper_->GetAcceptLangs();
}
void ContentBrowserClientEfl::SetAcceptLangs(const std::string& accept_langs) {
- if (accept_langs.empty() || accept_langs_ == accept_langs)
- return;
-
- accept_langs_ = accept_langs;
-
- if (preferred_langs_.empty())
- NotifyAcceptLangsChanged();
+ accept_langs_helper_->SetAcceptLangs(accept_langs);
}
void ContentBrowserClientEfl::SetPreferredLangs(
const std::string& preferred_langs) {
- if (preferred_langs_ == preferred_langs)
- return;
-
- preferred_langs_ = preferred_langs;
-
- NotifyAcceptLangsChanged();
+ accept_langs_helper_->SetPreferredLangs(preferred_langs);
}
void ContentBrowserClientEfl::AddAcceptLangsChangedCallback(
- AcceptLangsChangedCallback callback) {
- if (callback)
- accept_langs_changed_callbacks_.push_back(std::move(callback));
+ AcceptLanguagesHelper::AcceptLangsChangedCallback callback) {
+ accept_langs_helper_->AddAcceptLangsChangedCallback(std::move(callback));
}
void ContentBrowserClientEfl::RemoveAcceptLangsChangedCallback(
- AcceptLangsChangedCallback callback) {
-#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
- for (size_t i = 0; i < accept_langs_changed_callbacks_.size(); ++i) {
- if (accept_langs_changed_callbacks_[i] == callback) {
- accept_langs_changed_callbacks_.erase(
- accept_langs_changed_callbacks_.begin() + i);
- return;
- }
- }
-#endif
-}
-
-void ContentBrowserClientEfl::NotifyAcceptLangsChanged() {
- std::vector<AcceptLangsChangedCallback> callbacks;
- callbacks.swap(accept_langs_changed_callbacks_);
-
- for (auto& callback : callbacks) {
- if (preferred_langs_.empty())
- std::move(callback).Run(accept_langs_);
- else
- std::move(callback).Run(preferred_langs_);
- }
+ AcceptLanguagesHelper::AcceptLangsChangedCallback callback) {
+ accept_langs_helper_->RemoveAcceptLangsChangedCallback(std::move(callback));
}
std::unique_ptr<LoginDelegate> ContentBrowserClientEfl::CreateLoginDelegate(
class BrowserMainPartsEfl;
class NotificationControllerEfl;
class SharedURLLoaderFactoryEfl;
-
#if defined(TIZEN_WEB_SPEECH_RECOGNITION)
class SpeechRecognitionManagerDelegate;
#endif
-
class WebContents;
class WebContentsView;
-class ContentBrowserClientEfl : public ContentBrowserClient {
+class AcceptLanguagesHelper {
public:
- typedef void (*Notification_Show_Callback)(Ewk_Notification*, void*);
- typedef void (*Notification_Cancel_Callback)(uint64_t, void*);
+ using AcceptLangsChangedCallback =
+ base::OnceCallback<void(const std::string&)>;
+ AcceptLanguagesHelper();
+ ~AcceptLanguagesHelper();
+
+ void SetAcceptLangs(const std::string& accept_langs);
+ void SetPreferredLangs(const std::string& preferred_langs);
+ std::string GetAcceptLangs();
+ void AddAcceptLangsChangedCallback(AcceptLangsChangedCallback callback);
+ void RemoveAcceptLangsChangedCallback(AcceptLangsChangedCallback callback);
+
+ private:
+ void NotifyAcceptLangsChanged();
+ std::string accept_langs_;
+ std::string preferred_langs_;
+ std::vector<AcceptLangsChangedCallback> accept_langs_changed_callbacks_;
+};
+
+class ContentBrowserClientEfl : public ContentBrowserClient {
+ public:
ContentBrowserClientEfl();
~ContentBrowserClientEfl() override;
ContentBrowserClientEfl(const ContentBrowserClientEfl&) = delete;
ContentBrowserClientEfl& operator=(const ContentBrowserClientEfl&) = delete;
- typedef base::OnceCallback<void(const std::string&)>
- AcceptLangsChangedCallback;
+ // ContentBrowserClient implementations.
std::unique_ptr<BrowserMainParts> CreateBrowserMainParts(
bool is_integration_test) override;
- // Allows the embedder to pass extra command line flags.
- // switches::kProcessType will already be set at this point.
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id) override;
-
bool CanCreateWindow(RenderFrameHost* opener,
const GURL& opener_url,
const GURL& opener_top_level_frame_url,
bool is_main_frame_request,
bool strict_enforcement,
base::OnceCallback<void(CertificateRequestResultType)> callback) override;
-
- PlatformNotificationService* GetPlatformNotificationService(
- BrowserContext* browser_context);
-
- NotificationControllerEfl* GetNotificationController() const;
-
bool AllowGetCookie(const GURL& url,
const GURL& first_party,
const net::CookieList& cookie_list,
ResourceContext* context,
int render_process_id,
int render_frame_id);
-
bool AllowSetCookie(const GURL& url,
const GURL& first_party,
const net::CanonicalCookie& cookie,
ResourceContext* context,
int render_process_id,
int render_frame_id);
-
void OverrideWebkitPrefs(WebContents* web_contents,
blink::web_pref::WebPreferences* prefs);
-
void RenderProcessWillLaunch(RenderProcessHost* host) override;
-
void SetCertificatePem(const net::SSLInfo& ssl_info,
int render_process_id,
int render_view_id);
-
DevToolsManagerDelegate* GetDevToolsManagerDelegate();
-
std::string GetApplicationLocale() override;
-
std::unique_ptr<WebContentsViewDelegate> GetWebContentsViewDelegate(
WebContents* web_contents) override;
-
- void SetBrowserContext(BrowserContext* context);
- void CleanUpBrowserContext();
-
- virtual std::unique_ptr<LoginDelegate> CreateLoginDelegate(
+ std::unique_ptr<LoginDelegate> CreateLoginDelegate(
const net::AuthChallengeInfo& auth_info,
WebContents* web_contents,
const GlobalRequestID& request_id,
scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) override;
-
std::string GetProduct() override;
std::string GetUserAgent() override;
-
- std::string GetAcceptLangs(BrowserContext* context) override;
+ NotificationControllerEfl* GetNotificationController() const;
+ void SetBrowserContext(BrowserContext* context);
+ void CleanUpBrowserContext();
void SetAcceptLangs(const std::string& accept_langs);
void SetPreferredLangs(const std::string& preferred_langs);
- void AddAcceptLangsChangedCallback(AcceptLangsChangedCallback callback);
- void RemoveAcceptLangsChangedCallback(AcceptLangsChangedCallback callback);
+ void AddAcceptLangsChangedCallback(
+ AcceptLanguagesHelper::AcceptLangsChangedCallback callback);
+ void RemoveAcceptLangsChangedCallback(
+ AcceptLanguagesHelper::AcceptLangsChangedCallback callback);
std::vector<std::unique_ptr<NavigationThrottle>> CreateThrottlesForNavigation(
NavigationHandle* handle) override;
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id) override;
+ std::string GetAcceptLangs(BrowserContext* context) override;
private:
bool WillCreateURLLoaderFactory(
bool* bypass_redirect_checks,
bool* disable_secure_dns,
network::mojom::URLLoaderFactoryOverridePtr* factory_override) override;
-
scoped_refptr<network::SharedURLLoaderFactory>
GetSystemSharedURLLoaderFactory() override;
-
static void SetCertificatePemOnUIThread(int render_process_id,
int render_view_id,
std::string certificate);
- static void DispatchPopupBlockedOnUIThread(int render_process_id,
- const GURL& target_url);
-
- void NotifyAcceptLangsChanged();
- void AppendExtraCommandLineSwitchesInternal(base::CommandLine* command_line,
- int child_process_id);
-
- BrowserMainPartsEfl* browser_main_parts_efl_;
-
- std::unique_ptr<NotificationControllerEfl> notification_controller_;
+ BrowserMainPartsEfl* browser_main_parts_efl_ = nullptr;
std::unique_ptr<content::BrowserContext> browser_context_;
+ std::unique_ptr<NotificationControllerEfl> notification_controller_;
// URLLoaderFactory backed by the NetworkContext returned by GetContext(), so
// consumers don't all need to create their own factory.
scoped_refptr<SharedURLLoaderFactoryEfl> shared_url_loader_factory_;
- std::string accept_langs_;
- std::string preferred_langs_;
- std::vector<AcceptLangsChangedCallback> accept_langs_changed_callbacks_;
+ std::unique_ptr<AcceptLanguagesHelper> accept_langs_helper_;
bool shutting_down_ = false;
};
} // namespace content
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
+#include "browser_context_efl.h"
#include "common/web_contents_utils.h"
#include "content/browser/selection/selection_controller_efl.h"
#include "content/common/paths_efl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/render_process_host.h"
#include "context_menu_controller_efl.h"
#include "eweb_view.h"
#include "net/base/filename_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "private/ewk_context_menu_private.h"
+#include "third_party/blink/public/mojom/context_menu/context_menu.mojom.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_helper_efl.h"
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "browser/download_manager_delegate_efl.h"
+#include "download_manager_delegate_efl.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/logging.h"
#include "base/pickle.h"
#include "base/strings/utf_string_conversions.h"
+#include "browser/javascript_dialog_manager_efl.h"
#include "browser/javascript_interface/gin_native_bridge_dispatcher_host.h"
#include "browser/navigation_policy_handler_efl.h"
#include "browser/quota_permission_context_efl.h"
#include "browser/selectpicker/popup_menu_item_private.h"
#include "browser/web_view_browser_message_filter.h"
#include "browser/web_view_evas_handler.h"
+#include "browser_context_efl.h"
#include "common/content_client_efl.h"
#include "common/render_messages_ewk.h"
#include "common/version_info.h"
std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
- content::ContentBrowserClientEfl::AcceptLangsChangedCallback
+ content::AcceptLanguagesHelper::AcceptLangsChangedCallback
accept_langs_changed_callback_;
std::unique_ptr<aura::WindowTreeHost> host_;
#include "url/gurl.h"
#include "net/base/auth.h"
-#include "browser/login_delegate_efl.h"
+#include "login_delegate_efl.h"
/**
* @brief Structure used to send credential for authentication challenge.
*
#include "base/guid.h"
#include "base/strings/stringprintf.h"
#include "browser/autofill/personal_data_manager_factory.h"
+#include "browser_context_efl.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "eweb_view.h"
#include "ewk_autofill_profile_private.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/ttrace.h"
-#include "browser/favicon/favicon_database.h"
#include "browser/input_picker/color_chooser_efl.h"
#include "browser/javascript_dialog_manager_efl.h"
#include "browser/policy_response_delegate_efl.h"
+#include "browser_context_efl.h"
#include "common/render_messages_ewk.h"
-#include "components/favicon/core/favicon_url.h"
-#include "components/favicon_base/favicon_types.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/browser/manifest/manifest_manager_host.h"
+#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/content_switches_internal.h"
#include "content/common/render_messages_efl.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/favicon_status.h"
+#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_view_host.h"
#include "eweb_view.h"
#include "eweb_view_callbacks.h"
#include "net/base/load_states.h"
#include "net/http/http_response_headers.h"
-#include "printing/metafile_skia.h"
#include "private/ewk_certificate_private.h"
#include "private/ewk_console_message_private.h"
#include "private/ewk_custom_handlers_private.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "url/gurl.h"
+#include "web_contents_observer_efl.h"
#if BUILDFLAG(IS_TIZEN)
#include <app_control.h>
namespace content {
-void WritePdfDataToFile(printing::MetafileSkia* metafile,
- const base::FilePath& filename) {
-#if !defined(EWK_BRINGUP) // FIXME: m67 bringup
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-#endif
- DCHECK(metafile);
- base::File file(filename,
- base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
- metafile->SaveTo(&file);
- file.Close();
- delete metafile;
-}
-
-static bool IsMainFrame(RenderFrameHost* render_frame_host) {
- return !render_frame_host->GetParent();
-}
-
#if BUILDFLAG(IS_TIZEN) && defined(TIZEN_MULTIMEDIA_SUPPORT)
static const MediaStreamDevice* GetRequestedVideoDevice(
const std::string& device_id) {
#endif
WebContentsDelegateEfl::WebContentsDelegateEfl(EWebView* view)
- : WebContentsObserver(&view->web_contents()),
- web_view_(view),
- is_fullscreen_(false),
+ : web_view_(view),
web_contents_(view->web_contents()),
- did_render_frame_(false),
- did_first_visually_non_empty_paint_(false),
- document_created_(false),
- dialog_manager_(NULL),
- weak_ptr_factory_(this) {
+ contents_observer_(std::make_unique<WebContentsObserverEfl>(view, this)) {
#if defined(TIZEN_AUTOFILL_SUPPORT)
AutofillClientEfl::CreateForWebContents(&web_contents_);
AutofillClientEfl* autofill_client =
web_view_->SmartCallback<EWebViewCallbacks::LoadProgressFinished>().call();
}
-void WebContentsDelegateEfl::LoadProgressChanged(double progress) {
- web_view_->SetProgressValue(progress);
- web_view_->SmartCallback<EWebViewCallbacks::LoadProgress>().call(&progress);
-}
-
void WebContentsDelegateEfl::AddNewContents(
WebContents* source,
std::unique_ptr<WebContents> new_contents,
web_view_->InvokeAuthCallback(login_delegate, url, realm);
}
-void WebContentsDelegateEfl::DidStartNavigation(
- NavigationHandle* navigation_handle) {
- if (!navigation_handle->IsInMainFrame())
- return;
- web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadStarted>().call();
-}
-
-void WebContentsDelegateEfl::DidRedirectNavigation(
- NavigationHandle* navigation_handle) {
- if (!navigation_handle->IsInMainFrame())
- return;
- web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadRedirect>().call();
-}
-
-void WebContentsDelegateEfl::DidFinishNavigation(
- NavigationHandle* navigation_handle) {
- if (!navigation_handle->HasCommitted())
- return;
-
- if (navigation_handle->IsInMainFrame()) {
- web_view_->SmartCallback<EWebViewCallbacks::LoadCommitted>().call();
-
- if (!navigation_handle->IsSameDocument() &&
- !navigation_handle->IsErrorPage())
- web_view_->SmartCallback<EWebViewCallbacks::LoadStarted>().call();
- } else if (!navigation_handle->HasSubframeNavigationEntryCommitted()) {
- return;
- }
-
- if (navigation_handle->ShouldUpdateHistory())
- static_cast<BrowserContextEfl*>(web_contents_.GetBrowserContext())
- ->AddVisitedURLs(navigation_handle->GetRedirectChain());
-}
-
-void WebContentsDelegateEfl::DidFinishLoad(RenderFrameHost* render_frame_host,
- const GURL& validated_url) {
- if (!IsMainFrame(render_frame_host))
- return;
- web_view_->SmartCallback<EWebViewCallbacks::LoadFinished>().call();
-
- web_contents_.Focus();
-}
-
-void WebContentsDelegateEfl::DidFailLoad(RenderFrameHost* render_frame_host,
- const GURL& validated_url,
- int error_code) {
- if (!IsMainFrame(render_frame_host))
- return;
-
- web_view_->InvokeLoadError(validated_url, error_code,
- error_code == net::ERR_ABORTED);
-}
-
-void WebContentsDelegateEfl::DidUpdateFaviconURL(
- RenderFrameHost* render_frame_host,
- const std::vector<blink::mojom::FaviconURLPtr>& candidates) {
- // select and set proper favicon
- for (const auto& favicon : candidates) {
- if (!favicon->icon_url.is_valid())
- continue;
-
- if (favicon->icon_type == blink::mojom::FaviconIconType::kFavicon) {
- NavigationEntry* entry = web_contents_.GetController().GetVisibleEntry();
- if (!entry)
- return;
- entry->GetFavicon().url = favicon->icon_url;
- entry->GetFavicon().valid = true;
-
- // check/update the url and favicon url in favicon database
- FaviconDatabase::Instance()->SetFaviconURLForPageURL(favicon->icon_url,
- entry->GetURL());
-
- // download favicon if there is no such in database
- if (!FaviconDatabase::Instance()->ExistsForFaviconURL(
- favicon->icon_url)) {
- LOG(INFO) << "No favicon in database for URL: "
- << favicon->icon_url.spec();
- favicon_downloader_.reset(new FaviconDownloader(
- &web_contents_, favicon->icon_url,
- base::BindOnce(&WebContentsDelegateEfl::DidDownloadFavicon,
- weak_ptr_factory_.GetWeakPtr())));
- favicon_downloader_->Start();
- } else {
- web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
- }
- return;
- }
- }
-}
-
-void WebContentsDelegateEfl::DidDownloadFavicon(bool success,
- const GURL& icon_url,
- const SkBitmap& bitmap) {
- favicon_downloader_.reset();
- if (success) {
- FaviconDatabase::Instance()->SetBitmapForFaviconURL(bitmap, icon_url);
- // emit "icon,received"
- web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
- }
-}
-
void WebContentsDelegateEfl::RequestCertificateConfirm(
WebContents* /*web_contents*/,
int cert_error,
void WebContentsDelegateEfl::SetContentSecurityPolicy(
const std::string& policy,
Ewk_CSP_Header_Type header_type) {
- if (document_created_) {
-#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
- RenderViewHost* rvh = web_contents_.GetRenderViewHost();
- rvh->Send(new EwkViewMsg_SetCSP(rvh->GetRoutingID(), policy, header_type));
-#endif
- } else {
- DCHECK(!pending_content_security_policy_.get());
- pending_content_security_policy_.reset(
- new ContentSecurityPolicy(policy, header_type));
- }
+ contents_observer_->SetContentSecurityPolicy(policy, header_type);
}
void WebContentsDelegateEfl::FindReply(WebContents* web_contents,
#endif
}
-bool WebContentsDelegateEfl::OnMessageReceived(
- const IPC::Message& message,
- RenderFrameHost* render_frame_host) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateEfl, message)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_GetContentSecurityPolicy,
- OnGetContentSecurityPolicy)
- IPC_MESSAGE_HANDLER(EwkHostMsg_DidPrintPagesToPdf,
- OnPrintedMetafileReceived)
- IPC_MESSAGE_HANDLER(EwkHostMsg_WrtMessage, OnWrtPluginMessage)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_WrtSyncMessage,
- OnWrtPluginSyncMessage)
- IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeContentsSize,
- OnDidChangeContentsSize)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
-
- return handled;
-}
-
-bool WebContentsDelegateEfl::Send(IPC::Message* message) {
- if (!web_contents_.GetRenderViewHost()) {
- delete message;
- return false;
- }
-#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
- return web_contents_.GetRenderViewHost()->Send(message);
-#else
- return false;
-#endif
-}
-
-void WebContentsDelegateEfl::OnWrtPluginMessage(
- const Ewk_Wrt_Message_Data& data) {
- std::unique_ptr<Ewk_Wrt_Message_Data> p(new Ewk_Wrt_Message_Data);
- p->type = data.type;
- p->value = data.value;
- p->id = data.id;
- p->reference_id = data.reference_id;
-
- web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(
- p.get());
-}
-
-void WebContentsDelegateEfl::OnWrtPluginSyncMessage(
- const Ewk_Wrt_Message_Data& data,
- IPC::Message* reply) {
- Ewk_Wrt_Message_Data tmp = data;
- web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(&tmp);
- EwkHostMsg_WrtSyncMessage::WriteReplyParams(reply, tmp.value);
- Send(reply);
-}
-
void WebContentsDelegateEfl::DidFirstVisuallyNonEmptyPaint() {
did_first_visually_non_empty_paint_ = true;
web_view_->SmartCallback<EWebViewCallbacks::LoadNonEmptyLayoutFinished>()
did_render_frame_ = false;
}
-void WebContentsDelegateEfl::OnGetContentSecurityPolicy(
- IPC::Message* reply_msg) {
- document_created_ = true;
- if (!pending_content_security_policy_.get()) {
- EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(
- reply_msg, std::string(), EWK_DEFAULT_POLICY);
- } else {
- EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(
- reply_msg, pending_content_security_policy_->policy,
- pending_content_security_policy_->header_type);
- pending_content_security_policy_.reset();
- }
- Send(reply_msg);
-}
-
-void WebContentsDelegateEfl::OnPrintedMetafileReceived(
- const DidPrintPagesParams& params) {
-#if !defined(EWK_BRINGUP) // FIXME: m85 bringup
- base::SharedMemory shared_buf(params.metafile_data_handle, true);
- if (!shared_buf.Map(params.data_size)) {
- NOTREACHED() << "couldn't map";
- return;
- }
-
- std::unique_ptr<printing::MetafileSkia> metafile(
- new printing::MetafileSkia());
- if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
- NOTREACHED() << "Invalid metafile header";
- return;
- }
-
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::BindOnce(&WritePdfDataToFile, metafile.release(), params.filename));
-#endif
-}
-
-void WebContentsDelegateEfl::NavigationEntryCommitted(
- const LoadCommittedDetails& load_details) {
- web_view_->InvokeBackForwardListChangedCallback();
-}
-
-void WebContentsDelegateEfl::RenderViewCreated(
- RenderViewHost* render_view_host) {
- web_view_->RenderViewCreated(render_view_host);
-}
-
-void WebContentsDelegateEfl::RenderProcessGone(base::TerminationStatus status) {
- // See RenderWidgetHostViewEfl::RenderProcessGone.
- if (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
- status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
- status == base::TERMINATION_STATUS_PROCESS_CRASHED) {
- web_view_->HandleRendererProcessCrash();
- }
-}
-
bool WebContentsDelegateEfl::DidAddMessageToConsole(
WebContents* source,
blink::mojom::ConsoleMessageLevel level,
return false;
}
-void WebContentsDelegateEfl::TitleWasSet(NavigationEntry* entry) {
- if (entry)
- web_view_->GetBackForwardList()->UpdateItemWithEntry(entry);
-}
-
void WebContentsDelegateEfl::RequestManifestInfo(
Ewk_View_Request_Manifest_Callback callback,
void* user_data) {
}
}
-void WebContentsDelegateEfl::OnPageScaleFactorChanged(float page_scale_factor) {
- web_view_->DidChangePageScaleFactor(page_scale_factor);
-}
-
-void WebContentsDelegateEfl::OnDidChangeContentsSize(int width, int height) {
- web_view_->DidChangeContentsSize(width, height);
-}
-
} // namespace content
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WEB_CONTENTS_DELEGATE_EFL
-#define WEB_CONTENTS_DELEGATE_EFL
-
-#include <deque>
-
-#include "browser/favicon/favicon_downloader.h"
-#include "browser/javascript_dialog_manager_efl.h"
-#include "browser_context_efl.h"
-#include "content/browser/web_contents/web_contents_impl.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
+#ifndef WEB_CONTENTS_DELEGATE_EFL_H_
+#define WEB_CONTENTS_DELEGATE_EFL_H_
+
#include "content/public/browser/web_contents_delegate.h"
-#include "content/public/browser/web_contents_observer.h"
#include "eweb_view.h"
#include "private/ewk_manifest_private.h"
#include "public/ewk_view_internal.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "ui/base/ime/text_input_type.h"
-#include "url/gurl.h"
-class DidPrintPagesParams;
-class Ewk_Wrt_Message_Data;
class JavaScriptDialogManagerEfl;
namespace content {
-class WebContentsDelegateEfl : public WebContentsDelegate,
- public WebContentsObserver,
- public IPC::Sender {
+class WebContentsObserverEfl;
+
+class WebContentsDelegateEfl : public WebContentsDelegate {
public:
WebContentsDelegateEfl(EWebView*);
- ~WebContentsDelegateEfl() override;
+ ~WebContentsDelegateEfl();
WebContentsDelegateEfl(const WebContentsDelegateEfl&) = delete;
WebContentsDelegateEfl& operator=(const WebContentsDelegateEfl&) = delete;
void ExitFullscreenModeForTab(WebContents* web_contents) override;
bool IsFullscreenForTabOrPending(const WebContents* web_contents) override;
-#if defined(TIZEN_MULTIMEDIA_SUPPORT)
- virtual bool CheckMediaAccessPermission(WebContents* web_contents,
- const GURL& security_origin,
- MediaStreamType type) override;
-
- virtual void RequestMediaAccessPermission(
- WebContents* web_contents,
- const MediaStreamRequest& request,
- MediaResponseCallback callback) override;
-
- void RequestMediaAccessAllow(const MediaStreamRequest& request,
- MediaResponseCallback callback);
-
- void RequestMediaAccessDeny(const MediaStreamRequest& request,
- MediaResponseCallback callback);
-#endif
void RegisterProtocolHandler(RenderFrameHost* host,
const std::string& protocol,
const GURL& url,
const gfx::Rect& selection_rect,
int active_match_ordinal,
bool final_update) override;
-
void DidRenderFrame() override;
-
void RequestCertificateConfirm(
WebContents* web_contents,
int cert_error,
JavaScriptDialogManager* GetJavaScriptDialogManager(
WebContents* source) override;
-
void ActivateContents(WebContents* contents) override;
-
void OnUpdateSettings(const Ewk_Settings* settings);
void SetContentSecurityPolicy(const std::string& policy,
Ewk_CSP_Header_Type header_type);
- void DidFirstVisuallyNonEmptyPaint() override;
- void DidStartLoading() override;
+ void DidFirstVisuallyNonEmptyPaint();
+ void DidStartLoading();
- bool OnMessageReceived(const IPC::Message& message,
- RenderFrameHost* render_frame_host) override;
- void OnPrintedMetafileReceived(const DidPrintPagesParams& params);
- void NavigationEntryCommitted(
- const LoadCommittedDetails& load_details) override;
- void RenderViewCreated(RenderViewHost* render_view_host);
- void RenderProcessGone(base::TerminationStatus status);
bool DidAddMessageToConsole(WebContents* source,
blink::mojom::ConsoleMessageLevel level,
const std::u16string& message,
std::unique_ptr<ColorChooser> OpenColorChooser(
WebContents* web_contents,
SkColor color,
- const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions)
- override;
+ const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions);
#if !defined(EWK_BRINGUP) // FIXME: m76 bringup
void OpenDateTimeDialog(ui::TextInputType dialog_type,
double dialog_value,
#endif
bool PreHandleGestureEvent(WebContents* source,
const blink::WebGestureEvent& event) override;
+ EWebView* web_view() const { return web_view_; }
+ WebContents& web_contents() const { return web_contents_; }
- // WebContentsObserver---------------------------------------------------
- void DidStartNavigation(NavigationHandle* navigation_handle) override;
-
- void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
-
- void DidFinishNavigation(NavigationHandle* navigation_handle) override;
-
- void LoadProgressChanged(double progress) override;
- void DidFinishLoad(RenderFrameHost* render_frame_host,
- const GURL& validated_url) override;
- void OnPageScaleFactorChanged(float page_scale_factor) override;
-
- void DidFailLoad(RenderFrameHost* render_frame_host,
- const GURL& validated_url,
- int error_code) override;
-
- void DidUpdateFaviconURL(
- RenderFrameHost* render_frame_host,
- const std::vector<blink::mojom::FaviconURLPtr>& candidates) override;
-
- void TitleWasSet(content::NavigationEntry* entry) override;
-
+ void RequestManifestInfo(Ewk_View_Request_Manifest_Callback callback,
+ void* user_data);
void OnAuthRequired(const std::string& realm,
const GURL& url,
LoginDelegateEfl* login_delegate);
- // IPC::Sender-----------------------------------------------------------
- bool Send(IPC::Message* message) override;
-
- void DidDownloadFavicon(bool success,
- const GURL& icon_url,
- const SkBitmap& bitmap);
-
- EWebView* web_view() const { return web_view_; }
- WebContents& web_contents() const { return web_contents_; }
+#if defined(TIZEN_MULTIMEDIA_SUPPORT)
+ virtual bool CheckMediaAccessPermission(WebContents* web_contents,
+ const GURL& security_origin,
+ MediaStreamType type) override;
- void RequestManifestInfo(Ewk_View_Request_Manifest_Callback callback,
- void* user_data);
+ virtual void RequestMediaAccessPermission(
+ WebContents* web_contents,
+ const MediaStreamRequest& request,
+ MediaResponseCallback callback) override;
+ void RequestMediaAccessAllow(const MediaStreamRequest& request,
+ MediaResponseCallback callback);
+ void RequestMediaAccessDeny(const MediaStreamRequest& request,
+ MediaResponseCallback callback);
+#endif
private:
- void OnGetContentSecurityPolicy(IPC::Message* reply_msg);
- void OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data);
- void OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
- IPC::Message* reply);
- void OnDidChangeContentsSize(int width, int height);
-
void OnDidGetManifest(Ewk_View_Request_Manifest_Callback callback,
void* user_data,
const GURL& manifest_url,
bool is_fullscreen_;
WebContents& web_contents_;
- bool did_render_frame_;
- bool did_first_visually_non_empty_paint_;
-
- struct ContentSecurityPolicy {
- ContentSecurityPolicy(const std::string& p, Ewk_CSP_Header_Type type)
- : policy(p), header_type(type) {}
- std::string policy;
- Ewk_CSP_Header_Type header_type;
- };
+ bool did_render_frame_ = false;
+ bool did_first_visually_non_empty_paint_ = false;
+ std::unique_ptr<WebContentsObserverEfl> contents_observer_;
+ void* ime_window_ = nullptr;
GURL last_visible_url_;
- std::unique_ptr<ContentSecurityPolicy> pending_content_security_policy_;
- bool document_created_;
JavaScriptDialogManagerEfl* dialog_manager_ = nullptr;
- std::unique_ptr<FaviconDownloader> favicon_downloader_;
- base::WeakPtrFactory<WebContentsDelegateEfl> weak_ptr_factory_;
+ int rotation_ = -1;
std::unique_ptr<_Ewk_Certificate_Policy_Decision>
certificate_policy_decision_;
};
}
-#endif
+#endif // WEB_CONTENTS_DELEGATE_EFL_H_
--- /dev/null
+// Copyright 2022 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "web_contents_observer_efl.h"
+
+#include "base/task/bind_post_task.h"
+#include "browser/favicon/favicon_database.h"
+#include "browser/favicon/favicon_downloader.h"
+#include "browser_context_efl.h"
+#include "common/print_pages_params.h"
+#include "common/render_messages_ewk.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/public/browser/favicon_status.h"
+#include "content/public/browser/file_select_listener.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "eweb_view_callbacks.h"
+#include "ipc/ipc_message_macros.h"
+#include "printing/metafile_skia.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
+#include "url/gurl.h"
+
+#if defined(OS_TIZEN_TV_PRODUCT)
+#if !defined(EWK_BRINGUP)
+#include "devtools_port_manager.h"
+#endif
+#include "private/ewk_context_private.h"
+#endif
+
+#if defined(TIZEN_AUTOFILL_SUPPORT)
+#include "browser/autofill/autofill_client_efl.h"
+using autofill::AutofillClientEfl;
+#endif
+
+namespace content {
+
+static bool IsMainFrame(RenderFrameHost* render_frame_host) {
+ return !render_frame_host->GetParent();
+}
+
+WebContentsObserverEfl::WebContentsObserverEfl(EWebView* view,
+ WebContentsDelegateEfl* delegate)
+ : WebContentsObserver(&view->web_contents()),
+ web_view_(view),
+ web_contents_(view->web_contents()),
+ web_contents_delegate_(delegate),
+ weak_ptr_factory_(this) {}
+
+WebContentsObserverEfl::~WebContentsObserverEfl() = default;
+
+void WebContentsObserverEfl::SetContentSecurityPolicy(
+ const std::string& policy,
+ Ewk_CSP_Header_Type header_type) {
+ if (document_created_) {
+#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
+ RenderViewHost* rvh = web_contents_.GetRenderViewHost();
+ rvh->Send(new EwkViewMsg_SetCSP(rvh->GetRoutingID(), policy, header_type));
+#endif
+ } else {
+ DCHECK(!pending_content_security_policy_.get());
+ pending_content_security_policy_.reset(
+ new ContentSecurityPolicy(policy, header_type));
+ }
+}
+
+void WebContentsObserverEfl::DidStartNavigation(
+ NavigationHandle* navigation_handle) {
+ if (!navigation_handle->IsInMainFrame())
+ return;
+ web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadStarted>().call();
+}
+
+void WebContentsObserverEfl::DidRedirectNavigation(
+ NavigationHandle* navigation_handle) {
+ if (!navigation_handle->IsInMainFrame())
+ return;
+ web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadRedirect>().call();
+}
+
+void WebContentsObserverEfl::DidFinishNavigation(
+ NavigationHandle* navigation_handle) {
+ if (!navigation_handle->HasCommitted())
+ return;
+
+ if (navigation_handle->IsInMainFrame()) {
+ web_view_->SmartCallback<EWebViewCallbacks::LoadCommitted>().call();
+
+ if (!navigation_handle->IsSameDocument() &&
+ !navigation_handle->IsErrorPage())
+ web_view_->SmartCallback<EWebViewCallbacks::LoadStarted>().call();
+ } else if (!navigation_handle->HasSubframeNavigationEntryCommitted()) {
+ return;
+ }
+
+ if (navigation_handle->ShouldUpdateHistory())
+ static_cast<BrowserContextEfl*>(web_contents_.GetBrowserContext())
+ ->AddVisitedURLs(navigation_handle->GetRedirectChain());
+}
+
+void WebContentsObserverEfl::LoadProgressChanged(double progress) {
+ web_view_->SetProgressValue(progress);
+ web_view_->SmartCallback<EWebViewCallbacks::LoadProgress>().call(&progress);
+}
+
+void WebContentsObserverEfl::DidFinishLoad(RenderFrameHost* render_frame_host,
+ const GURL& validated_url) {
+ if (!IsMainFrame(render_frame_host))
+ return;
+ web_view_->SmartCallback<EWebViewCallbacks::LoadFinished>().call();
+
+ web_contents_.Focus();
+}
+
+void WebContentsObserverEfl::DidFailLoad(RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ int error_code) {
+ if (!IsMainFrame(render_frame_host))
+ return;
+
+ web_view_->InvokeLoadError(validated_url, error_code,
+ error_code == net::ERR_ABORTED);
+}
+
+void WebContentsObserverEfl::TitleWasSet(NavigationEntry* entry) {
+ if (entry)
+ web_view_->GetBackForwardList()->UpdateItemWithEntry(entry);
+}
+
+void WebContentsObserverEfl::OnPageScaleFactorChanged(float page_scale_factor) {
+ web_view_->DidChangePageScaleFactor(page_scale_factor);
+}
+
+void WebContentsObserverEfl::DidFirstVisuallyNonEmptyPaint() {
+ web_contents_delegate_->DidFirstVisuallyNonEmptyPaint();
+}
+
+void WebContentsObserverEfl::DidStartLoading() {
+ web_contents_delegate_->DidStartLoading();
+}
+
+void WebContentsObserverEfl::NavigationEntryCommitted(
+ const LoadCommittedDetails& load_details) {
+ web_view_->InvokeBackForwardListChangedCallback();
+}
+
+void WebContentsObserverEfl::PrimaryMainFrameRenderProcessGone(
+ base::TerminationStatus status) {
+ if (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
+ status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
+ status == base::TERMINATION_STATUS_PROCESS_CRASHED) {
+ web_view_->HandleRendererProcessCrash();
+ }
+}
+
+void WebContentsObserverEfl::RenderViewCreated(
+ RenderViewHost* render_view_host) {
+ web_view_->RenderViewCreated(render_view_host);
+}
+
+void WebContentsObserverEfl::DidUpdateFaviconURL(
+ RenderFrameHost* render_frame_host,
+ const std::vector<blink::mojom::FaviconURLPtr>& candidates) {
+ // select and set proper favicon
+ for (const auto& favicon : candidates) {
+ if (!favicon->icon_url.is_valid())
+ continue;
+
+ if (favicon->icon_type == blink::mojom::FaviconIconType::kFavicon) {
+ NavigationEntry* entry = web_contents_.GetController().GetVisibleEntry();
+ if (!entry)
+ return;
+ entry->GetFavicon().url = favicon->icon_url;
+ entry->GetFavicon().valid = true;
+
+ // check/update the url and favicon url in favicon database
+ FaviconDatabase::Instance()->SetFaviconURLForPageURL(favicon->icon_url,
+ entry->GetURL());
+
+ // download favicon if there is no such in database
+ if (!FaviconDatabase::Instance()->ExistsForFaviconURL(
+ favicon->icon_url)) {
+ LOG(INFO) << "No favicon in database for URL: "
+ << favicon->icon_url.spec();
+ favicon_downloader_.reset(new FaviconDownloader(
+ &web_contents_, favicon->icon_url,
+ base::BindOnce(&WebContentsObserverEfl::DidDownloadFavicon,
+ weak_ptr_factory_.GetWeakPtr())));
+ favicon_downloader_->Start();
+ } else {
+ web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
+ }
+ return;
+ }
+ }
+}
+
+bool WebContentsObserverEfl::OnMessageReceived(
+ const IPC::Message& message,
+ RenderFrameHost* render_frame_host) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(WebContentsObserverEfl, message)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_GetContentSecurityPolicy,
+ OnGetContentSecurityPolicy)
+ IPC_MESSAGE_HANDLER(EwkHostMsg_DidPrintPagesToPdf,
+ OnPrintedMetafileReceived)
+ IPC_MESSAGE_HANDLER(EwkHostMsg_WrtMessage, OnWrtPluginMessage)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_WrtSyncMessage,
+ OnWrtPluginSyncMessage)
+ IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeContentsSize,
+ OnDidChangeContentsSize)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+bool WebContentsObserverEfl::Send(IPC::Message* message) {
+ if (!web_contents_.GetRenderViewHost()) {
+ delete message;
+ return false;
+ }
+#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
+ return web_contents_.GetRenderViewHost()->Send(message);
+#else
+ return false;
+#endif
+}
+
+void WebContentsObserverEfl::OnGetContentSecurityPolicy(
+ IPC::Message* reply_msg) {
+ document_created_ = true;
+ if (!pending_content_security_policy_.get()) {
+ EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(
+ reply_msg, std::string(), EWK_DEFAULT_POLICY);
+ } else {
+ EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(
+ reply_msg, pending_content_security_policy_->policy,
+ pending_content_security_policy_->header_type);
+ pending_content_security_policy_.reset();
+ }
+ Send(reply_msg);
+}
+
+void WebContentsObserverEfl::OnPrintedMetafileReceived(
+ const DidPrintPagesParams& params) {
+#if !defined(EWK_BRINGUP) // FIXME: m85 bringup
+ base::SharedMemory shared_buf(params.metafile_data_handle, true);
+ if (!shared_buf.Map(params.data_size)) {
+ NOTREACHED() << "couldn't map";
+ return;
+ }
+
+ std::unique_ptr<printing::MetafileSkia> metafile(
+ new printing::MetafileSkia());
+ if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
+ NOTREACHED() << "Invalid metafile header";
+ return;
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::BindOnce(&WritePdfDataToFile, metafile.release(), params.filename));
+#endif
+}
+
+void WebContentsObserverEfl::OnWrtPluginMessage(
+ const Ewk_Wrt_Message_Data& data) {
+ std::unique_ptr<Ewk_Wrt_Message_Data> p(new Ewk_Wrt_Message_Data);
+ p->type = data.type;
+ p->value = data.value;
+ p->id = data.id;
+ p->reference_id = data.reference_id;
+
+ web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(
+ p.get());
+}
+
+void WebContentsObserverEfl::OnWrtPluginSyncMessage(
+ const Ewk_Wrt_Message_Data& data,
+ IPC::Message* reply) {
+ Ewk_Wrt_Message_Data tmp = data;
+ web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(&tmp);
+ EwkHostMsg_WrtSyncMessage::WriteReplyParams(reply, tmp.value);
+ Send(reply);
+}
+
+void WebContentsObserverEfl::OnDidChangeContentsSize(int width, int height) {
+ web_view_->DidChangeContentsSize(width, height);
+}
+
+void WebContentsObserverEfl::OnDidChangeFocusedNodeBounds(
+ const gfx::RectF& focused_node_bounds) {
+#if defined(TIZEN_AUTOFILL_SUPPORT)
+ if (AutofillClientEfl* autofill_client =
+ AutofillClientEfl::FromWebContents(&web_contents_)) {
+ autofill_client->DidChangeFocusedNodeBounds(focused_node_bounds);
+ }
+#endif
+}
+
+void WebContentsObserverEfl::DidDownloadFavicon(bool success,
+ const GURL& icon_url,
+ const SkBitmap& bitmap) {
+ favicon_downloader_.reset();
+ if (success) {
+ FaviconDatabase::Instance()->SetBitmapForFaviconURL(bitmap, icon_url);
+ // emit "icon,received"
+ web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
+ }
+}
+
+} // namespace content
--- /dev/null
+// Copyright 2022 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEB_CONTENTS_OBSERVER_EFL_H_
+#define WEB_CONTENTS_OBSERVER_EFL_H_
+
+#include <string>
+
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "eweb_view.h"
+
+class DidPrintPagesParams;
+class Ewk_Wrt_Message_Data;
+class FaviconDownloader;
+class GURL;
+class SkBitmap;
+
+namespace gfx {
+class Rect;
+}
+
+namespace content {
+
+class WebContentsDelegateEfl;
+
+class WebContentsObserverEfl : public WebContentsObserver, public IPC::Sender {
+ public:
+ explicit WebContentsObserverEfl(EWebView* view,
+ WebContentsDelegateEfl* delegate);
+ WebContentsObserverEfl(const WebContentsObserverEfl&) = delete;
+ WebContentsObserverEfl& operator=(const WebContentsObserverEfl&) = delete;
+ ~WebContentsObserverEfl() override;
+
+ void SetContentSecurityPolicy(const std::string& policy,
+ Ewk_CSP_Header_Type header_type);
+
+ // IPC::Sender-----------------------------------------------------------
+ bool Send(IPC::Message* message) override;
+
+ private:
+ // WebContentsObserver overrides:
+ void DidStartNavigation(NavigationHandle* navigation_handle) override;
+ void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
+ void DidFinishNavigation(NavigationHandle* navigation_handle) override;
+ void LoadProgressChanged(double progress) override;
+ void DidFinishLoad(RenderFrameHost* render_frame_host,
+ const GURL& validated_url) override;
+ void DidFailLoad(RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ int error_code) override;
+ void TitleWasSet(NavigationEntry* entry) override;
+ void OnPageScaleFactorChanged(float page_scale_factor) override;
+ void DidFirstVisuallyNonEmptyPaint() override;
+ void DidStartLoading() override;
+ void NavigationEntryCommitted(
+ const LoadCommittedDetails& load_details) override;
+ void PrimaryMainFrameRenderProcessGone(
+ base::TerminationStatus status) override;
+ void RenderViewCreated(RenderViewHost* render_view_host);
+ void DidUpdateFaviconURL(
+ RenderFrameHost* render_frame_host,
+ const std::vector<blink::mojom::FaviconURLPtr>& candidates) override;
+ bool OnMessageReceived(const IPC::Message& message,
+ RenderFrameHost* render_frame_host) override;
+
+ // IPC message handlers:
+ void OnGetContentSecurityPolicy(IPC::Message* reply_msg);
+ void OnPrintedMetafileReceived(const DidPrintPagesParams& params);
+ void OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data);
+ void OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
+ IPC::Message* reply);
+ void OnDidChangeContentsSize(int width, int height);
+ void OnDidChangeFocusedNodeBounds(const gfx::RectF& focused_node_bounds);
+
+ void DidDownloadFavicon(bool success,
+ const GURL& icon_url,
+ const SkBitmap& bitmap);
+
+ struct ContentSecurityPolicy {
+ ContentSecurityPolicy(const std::string& p, Ewk_CSP_Header_Type type)
+ : policy(p), header_type(type) {}
+ std::string policy;
+ Ewk_CSP_Header_Type header_type;
+ };
+
+ bool document_created_ = false;
+ EWebView* web_view_;
+ WebContents& web_contents_;
+ std::unique_ptr<ContentSecurityPolicy> pending_content_security_policy_;
+ std::unique_ptr<FaviconDownloader> favicon_downloader_;
+ WebContentsDelegateEfl* web_contents_delegate_ = nullptr;
+ base::WeakPtrFactory<WebContentsObserverEfl> weak_ptr_factory_;
+};
+
+} // namespace content
+
+#endif // WEB_CONTENTS_OBSERVER_EFL_H_