Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/guestview/webview/webview_guest.cc

Issue 27408004: <webview>: Resolve relative paths as chrome-extension: URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed creis's comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/guestview/webview/webview_guest.h" 5 #include "chrome/browser/guestview/webview/webview_guest.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 9 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
9 #include "chrome/browser/extensions/extension_renderer_state.h" 10 #include "chrome/browser/extensions/extension_renderer_state.h"
10 #include "chrome/browser/extensions/script_executor.h" 11 #include "chrome/browser/extensions/script_executor.h"
11 #include "chrome/browser/favicon/favicon_tab_helper.h" 12 #include "chrome/browser/favicon/favicon_tab_helper.h"
12 #include "chrome/browser/guestview/guestview_constants.h" 13 #include "chrome/browser/guestview/guestview_constants.h"
13 #include "chrome/browser/guestview/webview/webview_constants.h" 14 #include "chrome/browser/guestview/webview/webview_constants.h"
14 #include "chrome/browser/guestview/webview/webview_permission_types.h" 15 #include "chrome/browser/guestview/webview/webview_permission_types.h"
15 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/native_web_keyboard_event.h" 18 #include "content/public/browser/native_web_keyboard_event.h"
18 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/resource_request_details.h" 23 #include "content/public/browser/resource_request_details.h"
23 #include "content/public/browser/site_instance.h" 24 #include "content/public/browser/site_instance.h"
24 #include "content/public/browser/storage_partition.h" 25 #include "content/public/browser/storage_partition.h"
25 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
28 #include "content/public/common/result_codes.h" 29 #include "content/public/common/result_codes.h"
30 #include "extensions/common/constants.h"
29 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
30 32
31 #if defined(ENABLE_PLUGINS) 33 #if defined(ENABLE_PLUGINS)
32 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" 34 #include "chrome/browser/guestview/webview/plugin_permission_helper.h"
33 #endif 35 #endif
34 36
35 using content::WebContents; 37 using content::WebContents;
36 38
37 namespace { 39 namespace {
38 40
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 100
99 void AttachWebViewHelpers(WebContents* contents) { 101 void AttachWebViewHelpers(WebContents* contents) {
100 FaviconTabHelper::CreateForWebContents(contents); 102 FaviconTabHelper::CreateForWebContents(contents);
101 #if defined(ENABLE_PLUGINS) 103 #if defined(ENABLE_PLUGINS)
102 PluginPermissionHelper::CreateForWebContents(contents); 104 PluginPermissionHelper::CreateForWebContents(contents);
103 #endif 105 #endif
104 } 106 }
105 107
106 } // namespace 108 } // namespace
107 109
108 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) 110 WebViewGuest::WebViewGuest(WebContents* guest_web_contents,
109 : GuestView(guest_web_contents), 111 const std::string& extension_id)
112 : GuestView(guest_web_contents, extension_id),
110 WebContentsObserver(guest_web_contents), 113 WebContentsObserver(guest_web_contents),
111 script_executor_(new extensions::ScriptExecutor(guest_web_contents, 114 script_executor_(new extensions::ScriptExecutor(guest_web_contents,
112 &script_observers_)), 115 &script_observers_)),
113 next_permission_request_id_(0), 116 next_permission_request_id_(0),
114 is_overriding_user_agent_(false) { 117 is_overriding_user_agent_(false) {
115 notification_registrar_.Add( 118 notification_registrar_.Add(
116 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 119 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
117 content::Source<WebContents>(guest_web_contents)); 120 content::Source<WebContents>(guest_web_contents));
118 121
119 notification_registrar_.Add( 122 notification_registrar_.Add(
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 WebContents* web_contents) { 546 WebContents* web_contents) {
544 content::BrowserThread::PostTask( 547 content::BrowserThread::PostTask(
545 content::BrowserThread::IO, FROM_HERE, 548 content::BrowserThread::IO, FROM_HERE,
546 base::Bind( 549 base::Bind(
547 &ExtensionRendererState::RemoveWebView, 550 &ExtensionRendererState::RemoveWebView,
548 base::Unretained(ExtensionRendererState::GetInstance()), 551 base::Unretained(ExtensionRendererState::GetInstance()),
549 web_contents->GetRenderProcessHost()->GetID(), 552 web_contents->GetRenderProcessHost()->GetID(),
550 web_contents->GetRoutingID())); 553 web_contents->GetRoutingID()));
551 } 554 }
552 555
556 GURL WebViewGuest::ResolveURL(const std::string& src) {
557 DCHECK(!extension_id().empty());
Charlie Reis 2013/10/29 21:11:39 nit: Just put a NOTREACHED() inside the if stateme
Fady Samuel 2013/10/30 19:48:52 Done.
558 if (extension_id().empty())
559 return GURL(src);
560 GURL default_url(base::StringPrintf("%s://%s/",
561 extensions::kExtensionScheme,
562 extension_id().c_str()));
563 return default_url.Resolve(src);
564 }
565
553 void WebViewGuest::SizeChanged(const gfx::Size& old_size, 566 void WebViewGuest::SizeChanged(const gfx::Size& old_size,
554 const gfx::Size& new_size) { 567 const gfx::Size& new_size) {
555 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 568 scoped_ptr<DictionaryValue> args(new DictionaryValue());
556 args->SetInteger(webview::kOldHeight, old_size.height()); 569 args->SetInteger(webview::kOldHeight, old_size.height());
557 args->SetInteger(webview::kOldWidth, old_size.width()); 570 args->SetInteger(webview::kOldWidth, old_size.width());
558 args->SetInteger(webview::kNewHeight, new_size.height()); 571 args->SetInteger(webview::kNewHeight, new_size.height());
559 args->SetInteger(webview::kNewWidth, new_size.width()); 572 args->SetInteger(webview::kNewWidth, new_size.width());
560 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); 573 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass()));
561 } 574 }
562 575
563 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() 576 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo()
564 : allowed_by_default(false) { 577 : allowed_by_default(false) {
565 } 578 }
566 579
567 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( 580 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo(
568 const PermissionResponseCallback& callback, 581 const PermissionResponseCallback& callback,
569 bool allowed_by_default) 582 bool allowed_by_default)
570 : callback(callback), 583 : callback(callback),
571 allowed_by_default(allowed_by_default) { 584 allowed_by_default(allowed_by_default) {
572 } 585 }
573 586
574 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { 587 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
575 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698