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

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

Issue 10941042: Browser plugin: Implement loadStart and loadAbort events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed extra space Created 8 years, 2 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"
(...skipping 25 matching lines...) Expand all
36 using WebKit::WebPoint; 36 using WebKit::WebPoint;
37 using WebKit::WebString; 37 using WebKit::WebString;
38 using WebKit::WebRect; 38 using WebKit::WebRect;
39 using WebKit::WebURL; 39 using WebKit::WebURL;
40 using WebKit::WebVector; 40 using WebKit::WebVector;
41 41
42 namespace content { 42 namespace content {
43 43
44 namespace { 44 namespace {
45 const char kCrashEventName[] = "crash"; 45 const char kCrashEventName[] = "crash";
46 const char kIsTopLevel[] = "isTopLevel";
47 const char kLoadAbortEventName[] = "loadAbort";
48 const char kLoadStartEventName[] = "loadStart";
46 const char kNavigationEventName[] = "navigation"; 49 const char kNavigationEventName[] = "navigation";
47 const char* kPartitionAttribute = "partition"; 50 const char kPartitionAttribute[] = "partition";
48 const char* kPersistPrefix = "persist:"; 51 const char kPersistPrefix[] = "persist:";
49 const char* kSrcAttribute = "src"; 52 const char kSrcAttribute[] = "src";
50 53 const char kType[] = "type";
54 const char kURL[] = "url";
51 } 55 }
52 56
53 BrowserPlugin::BrowserPlugin( 57 BrowserPlugin::BrowserPlugin(
54 int instance_id, 58 int instance_id,
55 RenderViewImpl* render_view, 59 RenderViewImpl* render_view,
56 WebKit::WebFrame* frame, 60 WebKit::WebFrame* frame,
57 const WebPluginParams& params) 61 const WebPluginParams& params)
58 : instance_id_(instance_id), 62 : instance_id_(instance_id),
59 render_view_(render_view), 63 render_view_(render_view),
60 container_(NULL), 64 container_(NULL),
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 v8::Local<v8::Value> param = 339 v8::Local<v8::Value> param =
336 v8::Local<v8::Value>::New(v8::String::New(src_.c_str())); 340 v8::Local<v8::Value>::New(v8::String::New(src_.c_str()));
337 container()->element().document().frame()-> 341 container()->element().document().frame()->
338 callFunctionEvenIfScriptDisabled(*it, 342 callFunctionEvenIfScriptDisabled(*it,
339 v8::Object::New(), 343 v8::Object::New(),
340 1, 344 1,
341 &param); 345 &param);
342 } 346 }
343 } 347 }
344 348
349 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
350 if (!HasListeners(kLoadStartEventName))
351 return;
352
353 EventListeners& listeners = event_listener_map_[kLoadStartEventName];
354 EventListeners::iterator it = listeners.begin();
355
356 v8::Context::Scope context_scope(v8::Context::New());
357 v8::HandleScope handle_scope;
358 // Construct the loadStart event object.
359 v8::Local<v8::Value> event =
360 v8::Local<v8::Object>::New(v8::Object::New());
361 v8::Local<v8::Object>::Cast(event)->Set(
362 v8::String::New(kURL, sizeof(kURL) - 1),
363 v8::String::New(url.spec().c_str(), url.spec().size()));
364 v8::Local<v8::Object>::Cast(event)->Set(
365 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
366 v8::Boolean::New(is_top_level));
367 for (; it != listeners.end(); ++it) {
368 // Fire the event listener.
369 container()->element().document().frame()->
370 callFunctionEvenIfScriptDisabled(*it,
371 v8::Object::New(),
372 1,
373 &event);
374 }
375 }
376
377 void BrowserPlugin::LoadAbort(const GURL& url,
378 bool is_top_level,
379 const std::string& type) {
380 if (!HasListeners(kLoadAbortEventName))
381 return;
382
383 EventListeners& listeners = event_listener_map_[kLoadAbortEventName];
384 EventListeners::iterator it = listeners.begin();
385
386 v8::Context::Scope context_scope(v8::Context::New());
387 v8::HandleScope handle_scope;
388 // Construct the loadAbort event object.
389 v8::Local<v8::Value> event =
390 v8::Local<v8::Object>::New(v8::Object::New());
391 v8::Local<v8::Object>::Cast(event)->Set(
392 v8::String::New(kURL, sizeof(kURL) - 1),
393 v8::String::New(url.spec().c_str(), url.spec().size()));
394 v8::Local<v8::Object>::Cast(event)->Set(
395 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
396 v8::Boolean::New(is_top_level));
397 v8::Local<v8::Object>::Cast(event)->Set(
398 v8::String::New(kType, sizeof(kType) - 1),
399 v8::String::New(type.c_str(), type.size()));
400 for (; it != listeners.end(); ++it) {
401 // Fire the event listener.
402 container()->element().document().frame()->
403 callFunctionEvenIfScriptDisabled(*it,
404 v8::Object::New(),
405 1,
406 &event);
407 }
408 }
409
345 void BrowserPlugin::AdvanceFocus(bool reverse) { 410 void BrowserPlugin::AdvanceFocus(bool reverse) {
346 // We do not have a RenderView when we are testing. 411 // We do not have a RenderView when we are testing.
347 if (render_view_) 412 if (render_view_)
348 render_view_->GetWebView()->advanceFocus(reverse); 413 render_view_->GetWebView()->advanceFocus(reverse);
349 } 414 }
350 415
351 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { 416 void BrowserPlugin::SetAcceptTouchEvents(bool accept) {
352 if (container()) 417 if (container())
353 container()->setIsAcceptingTouchEvents(accept); 418 container()->setIsAcceptingTouchEvents(accept);
354 } 419 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 void* notify_data) { 683 void* notify_data) {
619 } 684 }
620 685
621 void BrowserPlugin::didFailLoadingFrameRequest( 686 void BrowserPlugin::didFailLoadingFrameRequest(
622 const WebKit::WebURL& url, 687 const WebKit::WebURL& url,
623 void* notify_data, 688 void* notify_data,
624 const WebKit::WebURLError& error) { 689 const WebKit::WebURLError& error) {
625 } 690 }
626 691
627 } // namespace content 692 } // 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