1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2014-2015 Samsung Electronics. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #include "content/browser/web_contents/web_contents_impl_efl.h"
8 #include "base/metrics/user_metrics.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/browser_plugin/browser_plugin_guest.h"
11 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
12 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
13 #include "content/browser/renderer_host/navigation_entry_impl.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h"
15 #include "content/browser/web_contents/web_contents_view.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_plugin_guest_manager.h"
18 #include "content/public/browser/content_browser_client.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/storage_partition.h"
22 #include "content/public/browser/web_contents_delegate.h"
23 #include "content/public/browser/web_contents_efl_delegate.h"
24 #include "content/public/common/content_client.h"
25 #include "content/public/common/result_codes.h"
27 // Majority of the code in this file was taken directly from
28 // WebContentsImpl::CreateNewWindow. Compared to the original, the function
29 // was split into 3 major parts which can be executed independently. The
31 // * WebContentsImplEfl::CreateNewWindow - Handle parts until the actual
32 // decision regarding if the window should be created or not.
33 // * WebContentsImplEfl::HandleNewWindowRequest - Handle positive/negative
34 // decision regarding the window. Either continue processing the request or
36 // * WebContentsImplEfl::HandleNewWebContentsCreate - Create new WebContents
38 // The execution of parts 2 and 3 is controlled by the user of the API through
39 // WebContentsDelegate ShouldCreateWebContentsAsync and WebContentsCreatedAsync
42 // In case WebContentsDelegate returns false from ShouldCreateWebContentsAsync
43 // and WebContentsCreateAsync functions the call sequence is:
45 // + WebContentsImplEfl::CreateMewWimdow
46 // |-+ WebContentsImplEfl::HandleNewWindowRequesst
47 // |-+ WebContentsImplEfl::HandleNewWebContentsCreate
49 // All functions are called in a single sequence.
51 // In the oposite case, both ShouldCreateWebContentsAsync and
52 // WebContentsCreateAsyns return true:
54 // + WebContents::Impl::CreateNewWindow
56 // + WebContentsDelegate::WebContentsCreateCallback
57 // |-+ WebContentsImplEfl::HandleNewWindowRequest
59 // + WebContentsDelegate::WebContentsCreateAsync
60 // |-+ WebContentsImplEfl::HandleNewWebContentsCreate
62 // In this case the user of the API decides when to execute each stage of the
67 WebContentsImplEfl::WebContentsImplEfl(BrowserContext* browser_context,
69 : WebContentsImpl(browser_context), platform_data_(platform_data) {}
71 WebContentsImplEfl::~WebContentsImplEfl() = default;
73 void WebContentsImplEfl::SetEflDelegate(WebContentsEflDelegate* delegate) {
74 efl_delegate_.reset(delegate);
77 std::unique_ptr<WebContents> WebContentsImplEfl::Clone() {
78 NOTREACHED() << "Cloning WebContents is not supported in EFL port";
82 void WebContentsImplEfl::SetUserAgentOverride(
83 const blink::UserAgentOverride& ua_override,
84 bool override_in_new_tabs) {}
86 WebContentsImpl* WebContentsImplEfl::CreateWebContentsForNewWindow(
87 BrowserContext* browser_context,
88 RenderFrameHostImpl* opener_rfh) {
89 WebContentsImplEfl* parent_contents = static_cast<WebContentsImplEfl*>(
90 WebContents::FromRenderFrameHost(opener_rfh));
91 WebContentsImpl* contents = new WebContentsImplEfl(
92 browser_context, parent_contents->GetPlatformDataForNewWindow());
93 parent_contents->SetWebContentsForNewWindow(contents);
97 FrameTree* WebContentsImplEfl::CreateNewWindow(
98 RenderFrameHostImpl* opener,
99 const mojom::CreateNewWindowParams& params,
100 bool is_new_browsing_instance,
101 bool has_user_gesture,
102 SessionStorageNamespace* session_storage_namespace) {
103 // Added for EFL implementation
104 LOG(INFO) << __FUNCTION__ << ", opener:" << opener
105 << ", target url: " << params.target_url;
106 WebContents* new_contents = nullptr;
107 WebContentsEflDelegate::WebContentsCreateCallback callback =
108 base::BindRepeating(&WebContentsImplEfl::HandleNewWebContentsCreate,
109 base::Unretained(this), opener, std::cref(params),
110 is_new_browsing_instance, has_user_gesture,
111 base::RetainedRef(session_storage_namespace),
115 if (efl_delegate_->WebContentsCreateAsync(std::move(callback))) {
116 DCHECK(new_contents);
118 static_cast<WebContentsImpl*>(new_contents)->GetPrimaryFrameTree());
123 // End of EFL port specific code.
125 // Added for EFL implementation of WebContentsImpl. In non EFL version
126 // contents of HandleNewWebContentsCreate would come here.
127 std::move(callback).Run(nullptr);
128 return &(static_cast<WebContentsImpl*>(new_contents)->GetPrimaryFrameTree());
131 WebContents* WebContentsImplEfl::HandleNewWebContentsCreate(
132 RenderFrameHostImpl* opener,
133 const mojom::CreateNewWindowParams& params,
134 bool is_new_browsing_instance,
135 bool has_user_gesture,
136 SessionStorageNamespace* session_storage_namespace,
137 WebContents** new_contents_out,
138 void* platform_data) {
139 platform_data_for_new_window_ = platform_data;
140 WebContentsImpl::CreateNewWindow(opener, params, is_new_browsing_instance,
141 has_user_gesture, session_storage_namespace);
142 *new_contents_out = web_contents_for_new_window_;
143 return web_contents_for_new_window_;
146 } // namespace content