OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 #include "ui/surface/transport_dib.h" | 48 #include "ui/surface/transport_dib.h" |
49 #include "webkit/common/resource_type.h" | 49 #include "webkit/common/resource_type.h" |
50 | 50 |
51 #if defined(OS_MACOSX) | 51 #if defined(OS_MACOSX) |
52 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 52 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
53 #endif | 53 #endif |
54 | 54 |
55 namespace content { | 55 namespace content { |
56 | 56 |
57 // static | 57 // static |
58 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 58 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
smo
2013/11/12 21:25:02
If supported, use "nullptr" instead of NULL everyw
lazyboy
2013/11/13 01:18:16
It isn't.
| |
59 | 59 |
60 // Parent class for the various types of permission requests, each of which | 60 // Parent class for the various types of permission requests, each of which |
61 // should be able to handle the response to their permission request. | 61 // should be able to handle the response to their permission request. |
62 class BrowserPluginGuest::PermissionRequest : | 62 class BrowserPluginGuest::PermissionRequest : |
63 public base::RefCounted<BrowserPluginGuest::PermissionRequest> { | 63 public base::RefCounted<BrowserPluginGuest::PermissionRequest> { |
64 public: | 64 public: |
65 virtual void Respond(bool should_allow, const std::string& user_input) = 0; | 65 virtual void Respond(bool should_allow, const std::string& user_input) = 0; |
66 virtual bool AllowedByDefault() const { | 66 virtual bool AllowedByDefault() const { |
67 return false; | 67 return false; |
smo
2013/11/12 21:25:02
Fix indent.
lazyboy
2013/11/13 01:18:16
Done.
| |
68 } | 68 } |
69 protected: | 69 protected: |
70 PermissionRequest() { | 70 PermissionRequest() { |
71 RecordAction(UserMetricsAction("BrowserPlugin.Guest.PermissionRequest")); | 71 RecordAction(UserMetricsAction("BrowserPlugin.Guest.PermissionRequest")); |
72 } | 72 } |
73 virtual ~PermissionRequest() {} | 73 virtual ~PermissionRequest() {} |
74 // Friend RefCounted so that the dtor can be non-public. | 74 // Friend RefCounted so that the dtor can be non-public. |
75 friend class base::RefCounted<BrowserPluginGuest::PermissionRequest>; | 75 friend class base::RefCounted<BrowserPluginGuest::PermissionRequest>; |
76 }; | 76 }; |
77 | 77 |
(...skipping 24 matching lines...) Expand all Loading... | |
102 weak_ptr_factory_(weak_ptr_factory) { | 102 weak_ptr_factory_(weak_ptr_factory) { |
103 RecordAction( | 103 RecordAction( |
104 UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Geolocation")); | 104 UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Geolocation")); |
105 } | 105 } |
106 | 106 |
107 virtual void Respond(bool should_allow, | 107 virtual void Respond(bool should_allow, |
108 const std::string& user_input) OVERRIDE { | 108 const std::string& user_input) OVERRIDE { |
109 base::WeakPtr<BrowserPluginGuest> guest(weak_ptr_factory_->GetWeakPtr()); | 109 base::WeakPtr<BrowserPluginGuest> guest(weak_ptr_factory_->GetWeakPtr()); |
110 | 110 |
111 WebContents* web_contents = guest->embedder_web_contents(); | 111 WebContents* web_contents = guest->embedder_web_contents(); |
112 if (should_allow && web_contents) { | 112 if (should_allow && web_contents) { |
smo
2013/11/12 21:25:02
(no change needed)
Or
"web_contents != nullptr
lazyboy
2013/11/13 01:18:16
As mentioned above, no nullptr.
I can change it to
smo
2013/11/13 01:50:54
Consistency with existing code is fine.
| |
113 // If renderer side embedder decides to allow gelocation, we need to check | 113 // If renderer side embedder decides to allow gelocation, we need to check |
114 // if the app/embedder itself has geolocation access. | 114 // if the app/embedder itself has geolocation access. |
115 BrowserContext* browser_context = web_contents->GetBrowserContext(); | 115 BrowserContext* browser_context = web_contents->GetBrowserContext(); |
116 if (browser_context) { | 116 if (browser_context) { |
117 GeolocationPermissionContext* geolocation_context = | 117 GeolocationPermissionContext* geolocation_context = |
118 browser_context->GetGeolocationPermissionContext(); | 118 browser_context->GetGeolocationPermissionContext(); |
119 if (geolocation_context) { | 119 if (geolocation_context) { |
120 base::Callback<void(bool)> geolocation_callback = base::Bind( | 120 base::Callback<void(bool)> geolocation_callback = base::Bind( |
121 &BrowserPluginGuest::SetGeolocationPermission, | 121 &BrowserPluginGuest::SetGeolocationPermission, |
122 guest, | 122 guest, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 RenderViewHost* render_view_host, | 291 RenderViewHost* render_view_host, |
292 int url_request_id) { | 292 int url_request_id) { |
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
294 | 294 |
295 int render_process_id = render_view_host->GetProcess()->GetID(); | 295 int render_process_id = render_view_host->GetProcess()->GetID(); |
296 GlobalRequestID global_id(render_process_id, url_request_id); | 296 GlobalRequestID global_id(render_process_id, url_request_id); |
297 net::URLRequest* url_request = | 297 net::URLRequest* url_request = |
298 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 298 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
299 if (url_request) | 299 if (url_request) |
300 return url_request->url().possibly_invalid_spec(); | 300 return url_request->url().possibly_invalid_spec(); |
301 return std::string(); | 301 return std::string(); |
smo
2013/11/12 21:25:02
or
return "";
to make it more obvious what's
lazyboy
2013/11/13 01:18:16
Done.
| |
302 } | 302 } |
303 | 303 |
304 } // namespace | 304 } // namespace |
305 | 305 |
306 class BrowserPluginGuest::EmbedderWebContentsObserver | 306 class BrowserPluginGuest::EmbedderWebContentsObserver |
307 : public WebContentsObserver { | 307 : public WebContentsObserver { |
308 public: | 308 public: |
309 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) | 309 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) |
310 : WebContentsObserver(guest->embedder_web_contents()), | 310 : WebContentsObserver(guest->embedder_web_contents()), |
311 browser_plugin_guest_(guest) { | 311 browser_plugin_guest_(guest) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 // pending_new_windows_ set. To avoid mutating the set while iterating, we | 381 // pending_new_windows_ set. To avoid mutating the set while iterating, we |
382 // create a copy of the pending new windows set and iterate over the copy. | 382 // create a copy of the pending new windows set and iterate over the copy. |
383 PendingWindowMap pending_new_windows(pending_new_windows_); | 383 PendingWindowMap pending_new_windows(pending_new_windows_); |
384 // Clean up unattached new windows opened by this guest. | 384 // Clean up unattached new windows opened by this guest. |
385 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); | 385 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); |
386 it != pending_new_windows.end(); ++it) { | 386 it != pending_new_windows.end(); ++it) { |
387 it->first->Destroy(); | 387 it->first->Destroy(); |
388 } | 388 } |
389 // All pending windows should be removed from the set after Destroy() is | 389 // All pending windows should be removed from the set after Destroy() is |
390 // called on all of them. | 390 // called on all of them. |
391 DCHECK_EQ(0ul, pending_new_windows_.size()); | 391 DCHECK_EQ(0ul, pending_new_windows_.size()); |
smo
2013/11/12 21:25:02
(optional)
Or
DCHECK(pending_new_windows_.empt
lazyboy
2013/11/13 01:18:16
Done.
| |
392 } | 392 } |
393 | 393 |
394 void BrowserPluginGuest::LoadURLWithParams(WebContents* web_contents, | 394 void BrowserPluginGuest::LoadURLWithParams(WebContents* web_contents, |
395 const GURL& url, | 395 const GURL& url, |
396 const Referrer& referrer, | 396 const Referrer& referrer, |
397 PageTransition transition_type) { | 397 PageTransition transition_type) { |
398 NavigationController::LoadURLParams load_url_params(url); | 398 NavigationController::LoadURLParams load_url_params(url); |
399 load_url_params.referrer = referrer; | 399 load_url_params.referrer = referrer; |
400 load_url_params.transition_type = transition_type; | 400 load_url_params.transition_type = transition_type; |
401 load_url_params.extra_headers = std::string(); | 401 load_url_params.extra_headers = std::string(); |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1117 case BrowserPluginHostMsg_SetAutoSize::ID: | 1117 case BrowserPluginHostMsg_SetAutoSize::ID: |
1118 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: | 1118 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: |
1119 case BrowserPluginHostMsg_SetFocus::ID: | 1119 case BrowserPluginHostMsg_SetFocus::ID: |
1120 case BrowserPluginHostMsg_SetName::ID: | 1120 case BrowserPluginHostMsg_SetName::ID: |
1121 case BrowserPluginHostMsg_SetVisibility::ID: | 1121 case BrowserPluginHostMsg_SetVisibility::ID: |
1122 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: | 1122 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: |
1123 case BrowserPluginHostMsg_UpdateGeometry::ID: | 1123 case BrowserPluginHostMsg_UpdateGeometry::ID: |
1124 case BrowserPluginHostMsg_UpdateRect_ACK::ID: | 1124 case BrowserPluginHostMsg_UpdateRect_ACK::ID: |
1125 return true; | 1125 return true; |
1126 default: | 1126 default: |
1127 break; | 1127 break; |
smo
2013/11/12 21:25:02
return false;
then delete 1129...?
lazyboy
2013/11/13 01:18:16
Done.
| |
1128 } | 1128 } |
1129 return false; | 1129 return false; |
1130 } | 1130 } |
1131 | 1131 |
1132 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 1132 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
1133 bool handled = true; | 1133 bool handled = true; |
1134 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 1134 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
1135 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 1135 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
1136 OnHasTouchEventHandlers) | 1136 OnHasTouchEventHandlers) |
1137 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 1137 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1730 base::DictionaryValue request_info; | 1730 base::DictionaryValue request_info; |
1731 request_info.Set(browser_plugin::kRequestMethod, | 1731 request_info.Set(browser_plugin::kRequestMethod, |
1732 base::Value::CreateStringValue(request_method)); | 1732 base::Value::CreateStringValue(request_method)); |
1733 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1733 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
1734 | 1734 |
1735 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1735 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
1736 new DownloadRequest(callback), | 1736 new DownloadRequest(callback), |
1737 request_info); | 1737 request_info); |
1738 } | 1738 } |
1739 | 1739 |
1740 | |
1740 } // namespace content | 1741 } // namespace content |
OLD | NEW |