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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 10928237: Add support for parsing a 'partition' attribute on the <browser> tag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Testing Created 8 years, 3 months 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 | Annotate | Revision Log
OLDNEW
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 13 matching lines...) Expand all
35 using WebKit::WebString; 36 using WebKit::WebString;
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";
46 const char* kPartitionAttribute = "partition";
47 const char* kPersistPrefix = "persist:";
45 const char* kSrcAttribute = "src"; 48 const char* kSrcAttribute = "src";
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()),
62 process_id_(-1) { 66 process_id_(-1),
67 persist_storage_(false) {
63 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); 68 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
64 bindings_.reset(new BrowserPluginBindings(this)); 69 bindings_.reset(new BrowserPluginBindings(this));
65 70
66 std::string src; 71 ParseAttributes(params);
67 if (ParseSrcAttribute(params, &src))
68 SetSrcAttribute(src);
69 } 72 }
70 73
71 BrowserPlugin::~BrowserPlugin() { 74 BrowserPlugin::~BrowserPlugin() {
72 if (damage_buffer_) { 75 if (damage_buffer_) {
73 RenderProcess::current()->FreeTransportDIB(damage_buffer_); 76 RenderProcess::current()->FreeTransportDIB(damage_buffer_);
74 damage_buffer_ = NULL; 77 damage_buffer_ = NULL;
75 } 78 }
76 RemoveEventListeners(); 79 RemoveEventListeners();
77 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); 80 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_);
78 BrowserPluginManager::Get()->Send( 81 BrowserPluginManager::Get()->Send(
(...skipping 23 matching lines...) Expand all
102 instance_id_, 105 instance_id_,
103 parent_frame_, 106 parent_frame_,
104 src, 107 src,
105 gfx::Size(width(), height()))); 108 gfx::Size(width(), height())));
106 // Record that we sent a NavigateGuest message to embedder. Once we send 109 // Record that we sent a NavigateGuest message to embedder. Once we send
107 // such a message, subsequent SetSrcAttribute() calls must always send 110 // such a message, subsequent SetSrcAttribute() calls must always send
108 // NavigateGuest messages to the embedder (even if |src| is empty), so 111 // NavigateGuest messages to the embedder (even if |src| is empty), so
109 // resize works correctly for all cases (e.g. The embedder can reset the 112 // resize works correctly for all cases (e.g. The embedder can reset the
110 // guest's |src| to empty value, resize and then set the |src| to a 113 // guest's |src| to empty value, resize and then set the |src| to a
111 // non-empty value). 114 // non-empty value).
115 // Additionally, once this instance has navigated, the storage partition
116 // cannot be changed, so this value is used for enforcing this.
112 navigate_src_sent_ = true; 117 navigate_src_sent_ = true;
113 } 118 }
114 src_ = src; 119 src_ = src;
115 guest_crashed_ = false; 120 guest_crashed_ = false;
116 } 121 }
117 122
118 bool BrowserPlugin::ParseSrcAttribute( 123 std::string BrowserPlugin::GetPartitionAttribute() const {
119 const WebKit::WebPluginParams& params, 124 std::string value;
120 std::string* src) { 125 if (persist_storage_)
126 value.append(kPersistPrefix);
127
128 value.append(storage_partition_id_);
129 return value;
130 }
131
132 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id,
133 std::string& error_message) {
134 if (navigate_src_sent_) {
135 error_message =
136 "The object has already navigated, so its partition cannot be changed.";
137 return false;
138 }
139
140 std::string input = partition_id;
141
142 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
143 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
144 // remove the prefix without splicing in the middle of a multi-byte codepoint.
145 // We can use the rest of the string as UTF-8 encoded one.
146 if (StartsWithASCII(input, kPersistPrefix, true)) {
147 size_t index = input.find(":");
148 CHECK(index != std::string::npos);
149 // It is safe to do index + 1, since we tested for the full prefix above.
150 input = input.substr(index + 1);
151 if (input.empty()) {
152 error_message = "Invalid empty partition attribute.";
153 return false;
154 }
155 persist_storage_ = true;
156 } else {
157 persist_storage_ = false;
158 }
159
160 storage_partition_id_ = input;
161 return true;
162 }
163
164 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) {
165 std::string src;
166
121 // Get the src attribute from the attributes vector 167 // Get the src attribute from the attributes vector
122 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { 168 for (unsigned i = 0; i < params.attributeNames.size(); ++i) {
123 std::string attributeName = params.attributeNames[i].utf8(); 169 std::string attributeName = params.attributeNames[i].utf8();
124 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { 170 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) {
125 *src = params.attributeValues[i].utf8(); 171 src = params.attributeValues[i].utf8();
126 return true; 172 } else if (LowerCaseEqualsASCII(attributeName, kPartitionAttribute)) {
173 std::string error;
174 SetPartitionAttribute(params.attributeValues[i].utf8(), error);
127 } 175 }
128 } 176 }
129 return false; 177
178 // Set the 'src' attribute last, as it will set the has_navigated_ flag to
179 // true, which prevents changing the 'partition' attribute.
180 if (!src.empty())
181 SetSrcAttribute(src);
130 } 182 }
131 183
132 float BrowserPlugin::GetDeviceScaleFactor() const { 184 float BrowserPlugin::GetDeviceScaleFactor() const {
133 if (!render_view_) 185 if (!render_view_)
134 return 1.0f; 186 return 1.0f;
135 return render_view_->GetWebView()->deviceScaleFactor(); 187 return render_view_->GetWebView()->deviceScaleFactor();
136 } 188 }
137 189
138 void BrowserPlugin::RemoveEventListeners() { 190 void BrowserPlugin::RemoveEventListeners() {
139 EventListenerMap::iterator event_listener_map_iter = 191 EventListenerMap::iterator event_listener_map_iter =
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 void* notify_data) { 524 void* notify_data) {
473 } 525 }
474 526
475 void BrowserPlugin::didFailLoadingFrameRequest( 527 void BrowserPlugin::didFailLoadingFrameRequest(
476 const WebKit::WebURL& url, 528 const WebKit::WebURL& url,
477 void* notify_data, 529 void* notify_data,
478 const WebKit::WebURLError& error) { 530 const WebKit::WebURLError& error) {
479 } 531 }
480 532
481 } // namespace content 533 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | content/renderer/browser_plugin/browser_plugin_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698