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

Unified Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 299753011: Move allocate instance id to chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/browser_plugin/browser_plugin.cc
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
index 9f6f406584be76665c55e56617d63d57637f2410..c12d3b9d69e95e8f6b15ce7bc8076c230054854b 100644
--- a/content/renderer/browser_plugin/browser_plugin.cc
+++ b/content/renderer/browser_plugin/browser_plugin.cc
@@ -54,8 +54,6 @@ namespace content {
namespace {
-const char* kCustomPersistPartition = "persist:custom_plugin";
-
static std::string GetInternalEventName(const char* event_name) {
return base::StringPrintf("-internal-%s", event_name);
}
@@ -75,13 +73,10 @@ BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view,
sad_guest_(NULL),
guest_crashed_(false),
is_auto_size_state_dirty_(false),
- persist_storage_(false),
- valid_partition_id_(true),
content_window_routing_id_(MSG_ROUTING_NONE),
plugin_focused_(false),
visible_(true),
auto_navigate_(auto_navigate),
- before_first_navigation_(true),
mouse_locked_(false),
browser_plugin_manager_(render_view->GetBrowserPluginManager()),
embedder_frame_url_(frame->document().url()),
@@ -168,10 +163,6 @@ bool BrowserPlugin::GetAllowTransparencyAttribute() const {
return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency);
}
-std::string BrowserPlugin::GetSrcAttribute() const {
- return GetDOMAttributeValue(browser_plugin::kAttributeSrc);
-}
-
bool BrowserPlugin::GetAutoSizeAttribute() const {
return HasDOMAttribute(browser_plugin::kAttributeAutoSize);
}
@@ -232,10 +223,6 @@ int BrowserPlugin::GetAdjustedMinWidth() const {
return std::min(min_width, GetAdjustedMaxWidth());
}
-std::string BrowserPlugin::GetPartitionAttribute() const {
- return GetDOMAttributeValue(browser_plugin::kAttributePartition);
-}
-
void BrowserPlugin::ParseAllowTransparencyAttribute() {
if (!HasGuestInstanceID())
return;
@@ -251,43 +238,6 @@ void BrowserPlugin::ParseAllowTransparencyAttribute() {
opaque));
}
-bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) {
- if (!valid_partition_id_) {
- *error_message = browser_plugin::kErrorInvalidPartition;
- return false;
- }
- std::string src = GetSrcAttribute();
- if (src.empty())
- return true;
-
- // If we haven't created the guest yet, do so now. We will navigate it right
- // after creation. If |src| is empty, we can delay the creation until we
- // actually need it.
- if (!HasGuestInstanceID()) {
- // On initial navigation, we request an instance ID from the browser
- // process. We essentially ignore all subsequent calls to SetSrcAttribute
- // until we receive an instance ID. |before_first_navigation_|
- // prevents BrowserPlugin from allocating more than one instance ID.
- // Upon receiving an instance ID from the browser process, we continue
- // the process of navigation by populating the
- // BrowserPluginHostMsg_Attach_Params with the current state of
- // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the
- // browser process in order to create a new guest.
- if (before_first_navigation_) {
- browser_plugin_manager()->AllocateInstanceID(
- weak_ptr_factory_.GetWeakPtr());
- before_first_navigation_ = false;
- }
- return true;
- }
-
- browser_plugin_manager()->Send(
- new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_,
- guest_instance_id_,
- src));
- return true;
-}
-
void BrowserPlugin::ParseAutoSizeAttribute() {
last_view_size_ = plugin_rect_.size();
is_auto_size_state_dirty_ = true;
@@ -333,21 +283,6 @@ void BrowserPlugin::UpdateGuestAutoSizeState(bool auto_size_enabled) {
resize_guest_params));
}
-void BrowserPlugin::OnInstanceIDAllocated(int guest_instance_id) {
- CHECK(guest_instance_id != browser_plugin::kInstanceIDNone);
-
- if (auto_navigate_) {
- scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue());
- Attach(guest_instance_id, params.Pass());
- return;
- }
-
- std::map<std::string, base::Value*> props;
- props[browser_plugin::kWindowID] =
- new base::FundamentalValue(guest_instance_id);
- TriggerEvent(browser_plugin::kEventInternalInstanceIDAllocated, &props);
Fady Samuel 2014/05/29 20:35:23 We can probably delete TriggerEvent too!
lazyboy 2014/05/30 05:48:21 Done.
-}
-
void BrowserPlugin::Attach(int guest_instance_id,
scoped_ptr<base::DictionaryValue> extra_params) {
CHECK(guest_instance_id != browser_plugin::kInstanceIDNone);
@@ -358,7 +293,6 @@ void BrowserPlugin::Attach(int guest_instance_id,
// This API may be called directly without setting the src attribute.
// In that case, we need to make sure we don't allocate another instance ID.
- before_first_navigation_ = false;
guest_instance_id_ = guest_instance_id;
browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this);
@@ -366,9 +300,6 @@ void BrowserPlugin::Attach(int guest_instance_id,
attach_params.focused = ShouldGuestBeFocused();
attach_params.visible = visible_;
attach_params.opaque = !GetAllowTransparencyAttribute();
- attach_params.storage_partition_id = storage_partition_id_;
- attach_params.persist_storage = persist_storage_;
- attach_params.src = GetSrcAttribute();
attach_params.embedder_frame_url = embedder_frame_url_;
GetSizeParams(&attach_params.auto_size_params,
&attach_params.resize_guest_params,
@@ -393,12 +324,6 @@ void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) {
void BrowserPlugin::OnAttachACK(
int guest_instance_id,
const BrowserPluginMsg_Attach_ACK_Params& params) {
- if (!params.storage_partition_id.empty()) {
- std::string partition_name =
- (params.persist_storage ? browser_plugin::kPersistPrefix : "") +
- params.storage_partition_id;
- UpdateDOMAttribute(browser_plugin::kAttributePartition, partition_name);
- }
attached_ = true;
}
@@ -565,50 +490,13 @@ NPObject* BrowserPlugin::GetContentWindow() const {
return guest_frame->windowObject();
}
-bool BrowserPlugin::HasNavigated() const {
- return !before_first_navigation_;
-}
-
bool BrowserPlugin::HasGuestInstanceID() const {
return guest_instance_id_ != browser_plugin::kInstanceIDNone;
}
-bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) {
- if (HasNavigated()) {
- *error_message = browser_plugin::kErrorAlreadyNavigated;
- return false;
- }
-
- std::string input;
- if (auto_navigate_)
- input = kCustomPersistPartition;
- else
- input = GetPartitionAttribute();
-
- // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
- // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
- // remove the prefix without splicing in the middle of a multi-byte codepoint.
- // We can use the rest of the string as UTF-8 encoded one.
- if (StartsWithASCII(input, browser_plugin::kPersistPrefix, true)) {
- size_t index = input.find(":");
- CHECK(index != std::string::npos);
- // It is safe to do index + 1, since we tested for the full prefix above.
- input = input.substr(index + 1);
- if (input.empty()) {
- valid_partition_id_ = false;
- *error_message = browser_plugin::kErrorInvalidPartition;
- return false;
- }
- persist_storage_ = true;
- } else {
- persist_storage_ = false;
- }
-
- valid_partition_id_ = true;
- storage_partition_id_ = input;
- return true;
-}
+// TODO(lazyboy): Need equivalent in web_view.js
+// Also write test.
bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) {
if (HasGuestInstanceID())
*error_message = browser_plugin::kErrorCannotRemovePartition;
@@ -622,16 +510,6 @@ void BrowserPlugin::ShowSadGraphic() {
container_->invalidate();
}
-void BrowserPlugin::ParseAttributes() {
- // TODO(mthiesse): Handle errors here?
- std::string error;
- ParsePartitionAttribute(&error);
-
- // Parse the 'src' attribute last, as it will set the has_navigated_ flag to
- // true, which prevents changing the 'partition' attribute.
- ParseSrcAttribute(&error);
-}
-
float BrowserPlugin::GetDeviceScaleFactor() const {
if (!render_view_.get())
return 1.0f;
@@ -717,6 +595,7 @@ blink::WebPluginContainer* BrowserPlugin::container() const {
}
bool BrowserPlugin::initialize(WebPluginContainer* container) {
+ printf("BP::initialize()\n");
if (!container)
return false;
@@ -731,7 +610,6 @@ bool BrowserPlugin::initialize(WebPluginContainer* container) {
bindings_.reset(new BrowserPluginBindings(this));
container_ = container;
container_->setWantsWheelEvents(true);
- ParseAttributes();
return true;
}
@@ -1047,9 +925,10 @@ void BrowserPlugin::didReceiveData(const char* data, int data_length) {
}
void BrowserPlugin::didFinishLoading() {
+ printf("BP::didFinishLoading(), will update partition attr.\n");
if (auto_navigate_) {
+ // web_view.js should pick this mutation.
UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_);
- ParseAttributes();
}
}

Powered by Google App Engine
This is Rietveld 408576698