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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 : instance_id_(instance_id), | 65 : instance_id_(instance_id), |
66 render_view_(render_view), | 66 render_view_(render_view), |
67 container_(NULL), | 67 container_(NULL), |
68 damage_buffer_(NULL), | 68 damage_buffer_(NULL), |
69 sad_guest_(NULL), | 69 sad_guest_(NULL), |
70 guest_crashed_(false), | 70 guest_crashed_(false), |
71 resize_pending_(false), | 71 resize_pending_(false), |
72 navigate_src_sent_(false), | 72 navigate_src_sent_(false), |
73 process_id_(-1), | 73 process_id_(-1), |
74 persist_storage_(false), | 74 persist_storage_(false), |
75 visible_(true) { | 75 visible_(true), |
| 76 current_nav_entry_index_(0), |
| 77 nav_entry_count_(0) { |
76 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 78 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
77 bindings_.reset(new BrowserPluginBindings(this)); | 79 bindings_.reset(new BrowserPluginBindings(this)); |
78 | 80 |
79 ParseAttributes(params); | 81 ParseAttributes(params); |
80 } | 82 } |
81 | 83 |
82 BrowserPlugin::~BrowserPlugin() { | 84 BrowserPlugin::~BrowserPlugin() { |
83 if (damage_buffer_) | 85 if (damage_buffer_) |
84 FreeDamageBuffer(); | 86 FreeDamageBuffer(); |
85 RemoveEventListeners(); | 87 RemoveEventListeners(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 144 |
143 std::string BrowserPlugin::GetPartitionAttribute() const { | 145 std::string BrowserPlugin::GetPartitionAttribute() const { |
144 std::string value; | 146 std::string value; |
145 if (persist_storage_) | 147 if (persist_storage_) |
146 value.append(kPersistPrefix); | 148 value.append(kPersistPrefix); |
147 | 149 |
148 value.append(storage_partition_id_); | 150 value.append(storage_partition_id_); |
149 return value; | 151 return value; |
150 } | 152 } |
151 | 153 |
| 154 bool BrowserPlugin::CanGoBack() const { |
| 155 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; |
| 156 } |
| 157 |
| 158 bool BrowserPlugin::CanGoForward() const { |
| 159 return current_nav_entry_index_ >= 0 && |
| 160 current_nav_entry_index_ < (nav_entry_count_ - 1); |
| 161 } |
| 162 |
152 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, | 163 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, |
153 std::string& error_message) { | 164 std::string& error_message) { |
154 if (navigate_src_sent_) { | 165 if (navigate_src_sent_) { |
155 error_message = | 166 error_message = |
156 "The object has already navigated, so its partition cannot be changed."; | 167 "The object has already navigated, so its partition cannot be changed."; |
157 return false; | 168 return false; |
158 } | 169 } |
159 | 170 |
160 std::string input = partition_id; | 171 std::string input = partition_id; |
161 | 172 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // called. See http://crbug.com/155044. | 348 // called. See http://crbug.com/155044. |
338 EventListeners listeners(event_listener_map_[kCrashEventName]); | 349 EventListeners listeners(event_listener_map_[kCrashEventName]); |
339 EventListeners::iterator it = listeners.begin(); | 350 EventListeners::iterator it = listeners.begin(); |
340 for (; it != listeners.end(); ++it) { | 351 for (; it != listeners.end(); ++it) { |
341 WebKit::WebFrame* frame = plugin.document().frame(); | 352 WebKit::WebFrame* frame = plugin.document().frame(); |
342 if (frame) | 353 if (frame) |
343 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); | 354 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
344 } | 355 } |
345 } | 356 } |
346 | 357 |
347 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { | 358 void BrowserPlugin::DidNavigate( |
348 src_ = url.spec(); | 359 const BrowserPluginMsg_DidNavigate_Params& params) { |
349 process_id_ = process_id; | 360 src_ = params.url.spec(); |
| 361 process_id_ = params.process_id; |
| 362 current_nav_entry_index_ = params.current_entry_index; |
| 363 nav_entry_count_ = params.entry_count; |
| 364 |
350 if (!HasListeners(kNavigationEventName)) | 365 if (!HasListeners(kNavigationEventName)) |
351 return; | 366 return; |
352 | 367 |
353 WebKit::WebElement plugin = container()->element(); | 368 WebKit::WebElement plugin = container()->element(); |
354 v8::HandleScope handle_scope; | 369 v8::HandleScope handle_scope; |
355 v8::Context::Scope context_scope( | 370 v8::Context::Scope context_scope( |
356 plugin.document().frame()->mainWorldScriptContext()); | 371 plugin.document().frame()->mainWorldScriptContext()); |
357 | 372 |
358 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size()); | 373 // Construct the navigation event object. |
| 374 v8::Local<v8::Object> event = v8::Object::New(); |
| 375 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 376 v8::String::New(src_.data(), src_.size())); |
| 377 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 378 v8::Boolean::New(params.is_top_level)); |
| 379 v8::Local<v8::Value> val = event; |
359 | 380 |
360 // TODO(fsamuel): Copying the event listeners is insufficent because | 381 // TODO(fsamuel): Copying the event listeners is insufficent because |
361 // new persistent handles are not created when the copy constructor is | 382 // new persistent handles are not created when the copy constructor is |
362 // called. See http://crbug.com/155044. | 383 // called. See http://crbug.com/155044. |
363 EventListeners listeners(event_listener_map_[kNavigationEventName]); | 384 EventListeners listeners(event_listener_map_[kNavigationEventName]); |
364 EventListeners::iterator it = listeners.begin(); | 385 EventListeners::iterator it = listeners.begin(); |
365 for (; it != listeners.end(); ++it) { | 386 for (; it != listeners.end(); ++it) { |
366 WebKit::WebFrame* frame = plugin.document().frame(); | 387 WebKit::WebFrame* frame = plugin.document().frame(); |
367 if (frame) { | 388 if (frame) { |
368 frame->callFunctionEvenIfScriptDisabled( | 389 frame->callFunctionEvenIfScriptDisabled( |
369 *it, v8::Object::New(), 1, ¶m); | 390 *it, v8::Object::New(), 1, &val); |
370 } | 391 } |
371 } | 392 } |
372 } | 393 } |
373 | 394 |
374 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 395 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
375 if (!HasListeners(kLoadStartEventName)) | 396 if (!HasListeners(kLoadStartEventName)) |
376 return; | 397 return; |
377 | 398 |
378 WebKit::WebElement plugin = container()->element(); | 399 WebKit::WebElement plugin = container()->element(); |
379 v8::HandleScope handle_scope; | 400 v8::HandleScope handle_scope; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 void* notify_data) { | 778 void* notify_data) { |
758 } | 779 } |
759 | 780 |
760 void BrowserPlugin::didFailLoadingFrameRequest( | 781 void BrowserPlugin::didFailLoadingFrameRequest( |
761 const WebKit::WebURL& url, | 782 const WebKit::WebURL& url, |
762 void* notify_data, | 783 void* notify_data, |
763 const WebKit::WebURLError& error) { | 784 const WebKit::WebURLError& error) { |
764 } | 785 } |
765 | 786 |
766 } // namespace content | 787 } // namespace content |
OLD | NEW |