Chromium Code Reviews| 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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #if defined (OS_WIN) | 9 #if defined (OS_WIN) |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #endif | 11 #endif |
| 12 #include "base/utf_string_conversions.h" | |
| 12 #include "content/common/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin_messages.h" |
| 13 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 14 #include "content/public/renderer/content_renderer_client.h" | 15 #include "content/public/renderer/content_renderer_client.h" |
| 15 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 16 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
| 16 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 17 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 17 #include "content/renderer/render_process_impl.h" | 18 #include "content/renderer/render_process_impl.h" |
| 18 #include "content/renderer/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
| 19 #include "skia/ext/platform_canvas.h" | 20 #include "skia/ext/platform_canvas.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 36 using WebKit::WebRect; | 37 using WebKit::WebRect; |
| 37 using WebKit::WebURL; | 38 using WebKit::WebURL; |
| 38 using WebKit::WebVector; | 39 using WebKit::WebVector; |
| 39 | 40 |
| 40 namespace content { | 41 namespace content { |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 const char kCrashEventName[] = "crash"; | 44 const char kCrashEventName[] = "crash"; |
| 44 const char kNavigationEventName[] = "navigation"; | 45 const char kNavigationEventName[] = "navigation"; |
| 45 const char* kSrcAttribute = "src"; | 46 const char* kSrcAttribute = "src"; |
| 47 const char* kPartitionAttribute = "partition"; | |
| 48 const char* kPersistPrefix = "persist:"; | |
|
Fady Samuel
2012/09/20 20:49:21
alphabetize.
nasko
2012/09/20 21:24:01
Done.
| |
| 49 | |
| 46 } | 50 } |
| 47 | 51 |
| 48 BrowserPlugin::BrowserPlugin( | 52 BrowserPlugin::BrowserPlugin( |
| 49 int instance_id, | 53 int instance_id, |
| 50 RenderViewImpl* render_view, | 54 RenderViewImpl* render_view, |
| 51 WebKit::WebFrame* frame, | 55 WebKit::WebFrame* frame, |
| 52 const WebPluginParams& params) | 56 const WebPluginParams& params) |
| 53 : instance_id_(instance_id), | 57 : instance_id_(instance_id), |
| 54 render_view_(render_view), | 58 render_view_(render_view), |
| 55 container_(NULL), | 59 container_(NULL), |
| 56 damage_buffer_(NULL), | 60 damage_buffer_(NULL), |
| 57 sad_guest_(NULL), | 61 sad_guest_(NULL), |
| 58 guest_crashed_(false), | 62 guest_crashed_(false), |
| 59 resize_pending_(false), | 63 resize_pending_(false), |
| 60 navigate_src_sent_(false), | 64 navigate_src_sent_(false), |
| 61 parent_frame_(frame->identifier()) { | 65 parent_frame_(frame->identifier()), |
| 66 persist_storage_(false) { | |
| 62 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 67 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
| 63 bindings_.reset(new BrowserPluginBindings(this)); | 68 bindings_.reset(new BrowserPluginBindings(this)); |
| 64 | 69 |
| 65 std::string src; | 70 ParseAttributes(params); |
| 66 if (ParseSrcAttribute(params, &src)) | |
| 67 SetSrcAttribute(src); | |
| 68 } | 71 } |
| 69 | 72 |
| 70 BrowserPlugin::~BrowserPlugin() { | 73 BrowserPlugin::~BrowserPlugin() { |
| 71 if (damage_buffer_) { | 74 if (damage_buffer_) { |
| 72 RenderProcess::current()->FreeTransportDIB(damage_buffer_); | 75 RenderProcess::current()->FreeTransportDIB(damage_buffer_); |
| 73 damage_buffer_ = NULL; | 76 damage_buffer_ = NULL; |
| 74 } | 77 } |
| 75 RemoveEventListeners(); | 78 RemoveEventListeners(); |
| 76 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); | 79 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); |
| 77 BrowserPluginManager::Get()->Send( | 80 BrowserPluginManager::Get()->Send( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 101 instance_id_, | 104 instance_id_, |
| 102 parent_frame_, | 105 parent_frame_, |
| 103 src, | 106 src, |
| 104 gfx::Size(width(), height()))); | 107 gfx::Size(width(), height()))); |
| 105 // Record that we sent a NavigateGuest message to embedder. Once we send | 108 // Record that we sent a NavigateGuest message to embedder. Once we send |
| 106 // such a message, subsequent SetSrcAttribute() calls must always send | 109 // such a message, subsequent SetSrcAttribute() calls must always send |
| 107 // NavigateGuest messages to the embedder (even if |src| is empty), so | 110 // NavigateGuest messages to the embedder (even if |src| is empty), so |
| 108 // resize works correctly for all cases (e.g. The embedder can reset the | 111 // resize works correctly for all cases (e.g. The embedder can reset the |
| 109 // guest's |src| to empty value, resize and then set the |src| to a | 112 // guest's |src| to empty value, resize and then set the |src| to a |
| 110 // non-empty value). | 113 // non-empty value). |
| 114 // Additionally, once this instance has navigated, the storage partition | |
| 115 // cannot be changed, so this value is used for enforcing this. | |
| 111 navigate_src_sent_ = true; | 116 navigate_src_sent_ = true; |
| 112 } | 117 } |
| 113 src_ = src; | 118 src_ = src; |
| 114 guest_crashed_ = false; | 119 guest_crashed_ = false; |
| 115 } | 120 } |
| 116 | 121 |
| 117 bool BrowserPlugin::ParseSrcAttribute( | 122 std::string BrowserPlugin::GetPartitionAttribute() const { |
| 118 const WebKit::WebPluginParams& params, | 123 std::string value; |
| 119 std::string* src) { | 124 if (persist_storage_) |
| 125 value.append(kPersistPrefix); | |
| 126 | |
| 127 value.append(storage_partition_id_); | |
| 128 return value; | |
| 129 } | |
| 130 | |
| 131 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, | |
| 132 std::string& error_message) { | |
| 133 if (navigate_src_sent_) { | |
| 134 error_message = | |
| 135 "The object has already navigated, so its partition cannot be changed."; | |
| 136 return false; | |
| 137 } | |
| 138 | |
| 139 std::string input = partition_id; | |
| 140 | |
| 141 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | |
| 142 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | |
| 143 // remove the prefix without splicing in the middle of a multi-byte codepoint. | |
| 144 // We can use the rest of the string as UTF-8 encoded one. | |
| 145 if (StartsWithASCII(input, kPersistPrefix, true)) { | |
| 146 size_t index = input.find(":"); | |
| 147 CHECK(index != std::string::npos); | |
| 148 // It is safe to do index + 1, since we tested for the full prefix above. | |
| 149 input = input.substr(index + 1); | |
| 150 if (input.empty()) { | |
| 151 error_message = "Invalid empty partition attribute."; | |
| 152 return false; | |
| 153 } | |
| 154 persist_storage_ = true; | |
| 155 } else { | |
| 156 persist_storage_ = false; | |
| 157 } | |
| 158 | |
| 159 storage_partition_id_ = input; | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 163 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) { | |
| 164 std::string src; | |
| 165 | |
| 120 // Get the src attribute from the attributes vector | 166 // Get the src attribute from the attributes vector |
| 121 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { | 167 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { |
| 122 std::string attributeName = params.attributeNames[i].utf8(); | 168 std::string attributeName = params.attributeNames[i].utf8(); |
| 123 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { | 169 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { |
| 124 *src = params.attributeValues[i].utf8(); | 170 src = params.attributeValues[i].utf8(); |
| 125 return true; | 171 } else if (LowerCaseEqualsASCII(attributeName, kPartitionAttribute)) { |
| 172 std::string error; | |
| 173 SetPartitionAttribute(params.attributeValues[i].utf8(), error); | |
| 126 } | 174 } |
| 127 } | 175 } |
| 128 return false; | 176 |
| 177 // Set the 'src' attribute last, as it will set the has_navigated_ flag to | |
| 178 // true, which prevents changing the 'partition' attribute. | |
| 179 if (!src.empty()) | |
| 180 SetSrcAttribute(src); | |
| 129 } | 181 } |
| 130 | 182 |
| 131 float BrowserPlugin::GetDeviceScaleFactor() const { | 183 float BrowserPlugin::GetDeviceScaleFactor() const { |
| 132 if (!render_view_) | 184 if (!render_view_) |
| 133 return 1.0f; | 185 return 1.0f; |
| 134 return render_view_->GetWebView()->deviceScaleFactor(); | 186 return render_view_->GetWebView()->deviceScaleFactor(); |
| 135 } | 187 } |
| 136 | 188 |
| 137 void BrowserPlugin::RemoveEventListeners() { | 189 void BrowserPlugin::RemoveEventListeners() { |
| 138 EventListenerMap::iterator event_listener_map_iter = | 190 EventListenerMap::iterator event_listener_map_iter = |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 void* notify_data) { | 505 void* notify_data) { |
| 454 } | 506 } |
| 455 | 507 |
| 456 void BrowserPlugin::didFailLoadingFrameRequest( | 508 void BrowserPlugin::didFailLoadingFrameRequest( |
| 457 const WebKit::WebURL& url, | 509 const WebKit::WebURL& url, |
| 458 void* notify_data, | 510 void* notify_data, |
| 459 const WebKit::WebURLError& error) { | 511 const WebKit::WebURLError& error) { |
| 460 } | 512 } |
| 461 | 513 |
| 462 } // namespace content | 514 } // namespace content |
| OLD | NEW |