OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
12 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" | 12 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" |
13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/menu_manager.h" | 15 #include "chrome/browser/extensions/menu_manager.h" |
15 #include "chrome/browser/extensions/script_executor.h" | 16 #include "chrome/browser/extensions/script_executor.h" |
16 #include "chrome/browser/favicon/favicon_tab_helper.h" | 17 #include "chrome/browser/favicon/favicon_tab_helper.h" |
17 #include "chrome/browser/guest_view/guest_view_constants.h" | 18 #include "chrome/browser/guest_view/guest_view_constants.h" |
18 #include "chrome/browser/guest_view/guest_view_manager.h" | 19 #include "chrome/browser/guest_view/guest_view_manager.h" |
19 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 20 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
20 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | 21 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
21 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 22 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
22 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" | 23 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" |
23 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" | 24 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" |
(...skipping 17 matching lines...) Expand all Loading... |
41 #include "content/public/browser/site_instance.h" | 42 #include "content/public/browser/site_instance.h" |
42 #include "content/public/browser/storage_partition.h" | 43 #include "content/public/browser/storage_partition.h" |
43 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
44 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
45 #include "content/public/browser/web_contents_delegate.h" | 46 #include "content/public/browser/web_contents_delegate.h" |
46 #include "content/public/common/media_stream_request.h" | 47 #include "content/public/common/media_stream_request.h" |
47 #include "content/public/common/page_zoom.h" | 48 #include "content/public/common/page_zoom.h" |
48 #include "content/public/common/result_codes.h" | 49 #include "content/public/common/result_codes.h" |
49 #include "content/public/common/stop_find_action.h" | 50 #include "content/public/common/stop_find_action.h" |
50 #include "content/public/common/url_constants.h" | 51 #include "content/public/common/url_constants.h" |
| 52 #include "extensions/browser/extension_system.h" |
51 #include "extensions/common/constants.h" | 53 #include "extensions/common/constants.h" |
| 54 #include "extensions/common/permissions/permissions_data.h" |
52 #include "ipc/ipc_message_macros.h" | 55 #include "ipc/ipc_message_macros.h" |
53 #include "net/base/escape.h" | 56 #include "net/base/escape.h" |
54 #include "net/base/net_errors.h" | 57 #include "net/base/net_errors.h" |
55 #include "third_party/WebKit/public/web/WebFindOptions.h" | 58 #include "third_party/WebKit/public/web/WebFindOptions.h" |
56 #include "ui/base/models/simple_menu_model.h" | 59 #include "ui/base/models/simple_menu_model.h" |
57 | 60 |
58 #if defined(ENABLE_PRINTING) | 61 #if defined(ENABLE_PRINTING) |
59 #if defined(ENABLE_FULL_PRINTING) | 62 #if defined(ENABLE_FULL_PRINTING) |
60 #include "chrome/browser/printing/print_preview_message_handler.h" | 63 #include "chrome/browser/printing/print_preview_message_handler.h" |
61 #include "chrome/browser/printing/print_view_manager.h" | 64 #include "chrome/browser/printing/print_view_manager.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // TODO(lazyboy): We need to expose some kind of enum equivalent of | 224 // TODO(lazyboy): We need to expose some kind of enum equivalent of |
222 // |command_id| instead of plain integers. | 225 // |command_id| instead of plain integers. |
223 item_value->SetInteger(webview::kMenuItemCommandId, | 226 item_value->SetInteger(webview::kMenuItemCommandId, |
224 menu_model.GetCommandIdAt(i)); | 227 menu_model.GetCommandIdAt(i)); |
225 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 228 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
226 items->Append(item_value); | 229 items->Append(item_value); |
227 } | 230 } |
228 return items.Pass(); | 231 return items.Pass(); |
229 } | 232 } |
230 | 233 |
| 234 bool WebViewGuest::CanEmbedderUseGuestView( |
| 235 const std::string& embedder_extension_id) { |
| 236 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 237 ExtensionService* service = |
| 238 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 239 const extensions::Extension* embedder_extension = |
| 240 service->GetExtensionById(embedder_extension_id, false); |
| 241 const extensions::PermissionsData* permissions_data = |
| 242 embedder_extension->permissions_data(); |
| 243 return permissions_data->HasAPIPermission( |
| 244 extensions::APIPermission::kWebView); |
| 245 } |
| 246 |
231 void WebViewGuest::CreateWebContents( | 247 void WebViewGuest::CreateWebContents( |
232 const std::string& embedder_extension_id, | 248 const std::string& embedder_extension_id, |
233 int embedder_render_process_id, | 249 int embedder_render_process_id, |
234 const base::DictionaryValue& create_params, | 250 const base::DictionaryValue& create_params, |
235 const WebContentsCreatedCallback& callback) { | 251 const WebContentsCreatedCallback& callback) { |
236 content::RenderProcessHost* embedder_render_process_host = | 252 content::RenderProcessHost* embedder_render_process_host = |
237 content::RenderProcessHost::FromID(embedder_render_process_id); | 253 content::RenderProcessHost::FromID(embedder_render_process_id); |
238 std::string storage_partition_id; | 254 std::string storage_partition_id; |
239 bool persist_storage = false; | 255 bool persist_storage = false; |
240 std::string storage_partition_string; | 256 std::string storage_partition_string; |
241 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); | 257 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); |
242 // Validate that the partition id coming from the renderer is valid UTF-8, | 258 // Validate that the partition id coming from the renderer is valid UTF-8, |
243 // since we depend on this in other parts of the code, such as FilePath | 259 // since we depend on this in other parts of the code, such as FilePath |
244 // creation. If the validation fails, treat it as a bad message and kill the | 260 // creation. If the validation fails, treat it as a bad message and kill the |
245 // renderer process. | 261 // renderer process. |
246 if (!base::IsStringUTF8(storage_partition_id)) { | 262 if (!base::IsStringUTF8(storage_partition_id)) { |
247 content::RecordAction( | 263 content::RecordAction( |
248 base::UserMetricsAction("BadMessageTerminate_BPGM")); | 264 base::UserMetricsAction("BadMessageTerminate_BPGM")); |
249 base::KillProcess( | 265 base::KillProcess( |
250 embedder_render_process_host->GetHandle(), | 266 embedder_render_process_host->GetHandle(), |
251 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 267 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 268 callback.Run(NULL); |
252 return; | 269 return; |
253 } | 270 } |
254 std::string url_encoded_partition = net::EscapeQueryParamValue( | 271 std::string url_encoded_partition = net::EscapeQueryParamValue( |
255 storage_partition_id, false); | 272 storage_partition_id, false); |
256 // The SiteInstance of a given webview tag is based on the fact that it's | 273 // The SiteInstance of a given webview tag is based on the fact that it's |
257 // a guest process in addition to which platform application the tag | 274 // a guest process in addition to which platform application the tag |
258 // belongs to and what storage partition is in use, rather than the URL | 275 // belongs to and what storage partition is in use, rather than the URL |
259 // that the tag is being navigated to. | 276 // that the tag is being navigated to. |
260 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 277 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
261 content::kGuestScheme, | 278 content::kGuestScheme, |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 bool allow, | 1238 bool allow, |
1222 const std::string& user_input) { | 1239 const std::string& user_input) { |
1223 WebViewGuest* guest = | 1240 WebViewGuest* guest = |
1224 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1241 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1225 if (!guest) | 1242 if (!guest) |
1226 return; | 1243 return; |
1227 | 1244 |
1228 if (!allow) | 1245 if (!allow) |
1229 guest->Destroy(); | 1246 guest->Destroy(); |
1230 } | 1247 } |
OLD | NEW |