60e7f331262b10dec4b5196ec16a22c8da2d03c9
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / web_contents / web_contents_impl_efl.cc
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.
5
6 #include "content/browser/web_contents/web_contents_impl_efl.h"
7
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"
26
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
30 // parts are:
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
35 //   cancel it.
36 // * WebContentsImplEfl::HandleNewWebContentsCreate - Create new WebContents
37 //
38 // The execution of parts 2 and 3 is controlled by the user of the API through
39 // WebContentsDelegate ShouldCreateWebContentsAsync and WebContentsCreatedAsync
40 // functions.
41 //
42 // In case WebContentsDelegate returns false from ShouldCreateWebContentsAsync
43 // and WebContentsCreateAsync functions the call sequence is:
44 //
45 // + WebContentsImplEfl::CreateMewWimdow
46 // |-+ WebContentsImplEfl::HandleNewWindowRequesst
47 //   |-+ WebContentsImplEfl::HandleNewWebContentsCreate
48 //
49 // All functions are called in a single sequence.
50 //
51 // In the oposite case, both ShouldCreateWebContentsAsync and
52 // WebContentsCreateAsyns return true:
53 //
54 // + WebContents::Impl::CreateNewWindow
55 // ...
56 // + WebContentsDelegate::WebContentsCreateCallback
57 // |-+ WebContentsImplEfl::HandleNewWindowRequest
58 // ...
59 // + WebContentsDelegate::WebContentsCreateAsync
60 // |-+ WebContentsImplEfl::HandleNewWebContentsCreate
61 //
62 // In this case the user of the API decides when to execute each stage of the
63 // sequence.
64
65 namespace content {
66
67 WebContentsImplEfl::WebContentsImplEfl(BrowserContext* browser_context,
68                                        void* platform_data)
69     : WebContentsImpl(browser_context), platform_data_(platform_data) {}
70
71 WebContentsImplEfl::~WebContentsImplEfl() = default;
72
73 void WebContentsImplEfl::SetEflDelegate(WebContentsEflDelegate* delegate) {
74   efl_delegate_.reset(delegate);
75 }
76
77 std::unique_ptr<WebContents> WebContentsImplEfl::Clone() {
78   NOTREACHED() << "Cloning WebContents is not supported in EFL port";
79   return nullptr;
80 }
81
82 void WebContentsImplEfl::SetUserAgentOverride(
83     const blink::UserAgentOverride& ua_override,
84     bool override_in_new_tabs) {}
85
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);
94   return contents;
95 }
96
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),
112                           &new_contents);
113
114   if (efl_delegate_) {
115     if (efl_delegate_->WebContentsCreateAsync(std::move(callback))) {
116       DCHECK(new_contents);
117       return &(
118           static_cast<WebContentsImpl*>(new_contents)->GetPrimaryFrameTree());
119     } else {
120       return nullptr;
121     }
122   }
123   // End of EFL port specific code.
124
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());
129 }
130
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_;
144 }
145
146 }  // namespace content