OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h" | 5 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "components/crx_file/id_util.h" | 8 #include "components/crx_file/id_util.h" |
9 #include "components/guest_view/browser/guest_view_event.h" | 9 #include "components/guest_view/browser/guest_view_event.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 using guest_view::GuestViewEvent; | 21 using guest_view::GuestViewEvent; |
22 using namespace extensions::core_api; | 22 using namespace extensions::core_api; |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 // static | 26 // static |
27 const char ExtensionViewGuest::Type[] = "extensionview"; | 27 const char ExtensionViewGuest::Type[] = "extensionview"; |
28 | 28 |
29 ExtensionViewGuest::ExtensionViewGuest( | 29 ExtensionViewGuest::ExtensionViewGuest( |
30 content::WebContents* owner_web_contents) | 30 content::WebContents* owner_web_contents) |
31 : GuestView<ExtensionViewGuest>(owner_web_contents), | 31 : GuestView<ExtensionViewGuest>(owner_web_contents) { |
32 extension_view_guest_delegate_( | |
33 extensions::ExtensionsAPIClient::Get() | |
34 ->CreateExtensionViewGuestDelegate(this)) { | |
35 } | 32 } |
36 | 33 |
37 ExtensionViewGuest::~ExtensionViewGuest() { | 34 ExtensionViewGuest::~ExtensionViewGuest() { |
38 } | 35 } |
39 | 36 |
40 // static | 37 // static |
41 GuestViewBase* ExtensionViewGuest::Create( | 38 GuestViewBase* ExtensionViewGuest::Create( |
42 content::WebContents* owner_web_contents) { | 39 content::WebContents* owner_web_contents) { |
43 return new ExtensionViewGuest(owner_web_contents); | 40 return new ExtensionViewGuest(owner_web_contents); |
44 } | 41 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 content::SiteInstance::CreateForURL(browser_context(), | 94 content::SiteInstance::CreateForURL(browser_context(), |
98 extension_url_); | 95 extension_url_); |
99 | 96 |
100 WebContents::CreateParams params(browser_context(), view_site_instance); | 97 WebContents::CreateParams params(browser_context(), view_site_instance); |
101 params.guest_delegate = this; | 98 params.guest_delegate = this; |
102 callback.Run(WebContents::Create(params)); | 99 callback.Run(WebContents::Create(params)); |
103 } | 100 } |
104 | 101 |
105 void ExtensionViewGuest::DidInitialize( | 102 void ExtensionViewGuest::DidInitialize( |
106 const base::DictionaryValue& create_params) { | 103 const base::DictionaryValue& create_params) { |
107 extension_function_dispatcher_.reset( | 104 ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents()); |
108 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | |
109 | |
110 if (extension_view_guest_delegate_) | |
111 extension_view_guest_delegate_->DidInitialize(); | |
112 | 105 |
113 ApplyAttributes(create_params); | 106 ApplyAttributes(create_params); |
114 } | 107 } |
115 | 108 |
116 void ExtensionViewGuest::DidAttachToEmbedder() { | 109 void ExtensionViewGuest::DidAttachToEmbedder() { |
117 ApplyAttributes(*attach_params()); | 110 ApplyAttributes(*attach_params()); |
118 } | 111 } |
119 | 112 |
120 const char* ExtensionViewGuest::GetAPINamespace() const { | 113 const char* ExtensionViewGuest::GetAPINamespace() const { |
121 return extensionview::kAPINamespace; | 114 return extensionview::kAPINamespace; |
(...skipping 28 matching lines...) Expand all Loading... |
150 | 143 |
151 void ExtensionViewGuest::DidNavigateMainFrame( | 144 void ExtensionViewGuest::DidNavigateMainFrame( |
152 const content::LoadCommittedDetails& details, | 145 const content::LoadCommittedDetails& details, |
153 const content::FrameNavigateParams& params) { | 146 const content::FrameNavigateParams& params) { |
154 if (attached() && (params.url.GetOrigin() != view_page_.GetOrigin())) { | 147 if (attached() && (params.url.GetOrigin() != view_page_.GetOrigin())) { |
155 bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(), | 148 bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(), |
156 bad_message::EVG_BAD_ORIGIN); | 149 bad_message::EVG_BAD_ORIGIN); |
157 } | 150 } |
158 } | 151 } |
159 | 152 |
160 bool ExtensionViewGuest::OnMessageReceived(const IPC::Message& message) { | |
161 bool handled = true; | |
162 IPC_BEGIN_MESSAGE_MAP(ExtensionViewGuest, message) | |
163 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
164 IPC_MESSAGE_UNHANDLED(handled = false) | |
165 IPC_END_MESSAGE_MAP() | |
166 return handled; | |
167 } | |
168 | |
169 // Private | |
170 void ExtensionViewGuest::OnRequest( | |
171 const ExtensionHostMsg_Request_Params& params) { | |
172 extension_function_dispatcher_->Dispatch(params, | |
173 web_contents()->GetRenderViewHost()); | |
174 } | |
175 | |
176 void ExtensionViewGuest::ApplyAttributes(const base::DictionaryValue& params) { | 153 void ExtensionViewGuest::ApplyAttributes(const base::DictionaryValue& params) { |
177 std::string src; | 154 std::string src; |
178 params.GetString(extensionview::kAttributeSrc, &src); | 155 params.GetString(extensionview::kAttributeSrc, &src); |
179 NavigateGuest(src, false /* force_navigation */); | 156 NavigateGuest(src, false /* force_navigation */); |
180 } | 157 } |
181 | 158 |
182 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |