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

Side by Side Diff: chrome/renderer/extensions/event_bindings.cc

Issue 6735004: Move extension messages to their own file and add a RenderViewObserver to start moving the extens... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
« no previous file with comments | « chrome/common/render_messages_params.cc ('k') | chrome/renderer/extensions/extension_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/extensions/event_bindings.h" 5 #include "chrome/renderer/extensions/event_bindings.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "chrome/common/extensions/extension_messages.h"
9 #include "chrome/common/extensions/extension_set.h" 10 #include "chrome/common/extensions/extension_set.h"
10 #include "chrome/common/render_messages.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "chrome/renderer/extensions/bindings_utils.h" 12 #include "chrome/renderer/extensions/bindings_utils.h"
13 #include "chrome/renderer/extensions/event_bindings.h" 13 #include "chrome/renderer/extensions/event_bindings.h"
14 #include "chrome/renderer/extensions/extension_process_bindings.h" 14 #include "chrome/renderer/extensions/extension_process_bindings.h"
15 #include "chrome/renderer/extensions/js_only_v8_extensions.h" 15 #include "chrome/renderer/extensions/js_only_v8_extensions.h"
16 #include "chrome/renderer/render_thread.h" 16 #include "chrome/renderer/render_thread.h"
17 #include "content/renderer/render_view.h" 17 #include "content/renderer/render_view.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "grit/renderer_resources.h" 19 #include "grit/renderer_resources.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 bool has_permission = 101 bool has_permission =
102 ExtensionProcessBindings::CurrentContextHasPermission(event_name); 102 ExtensionProcessBindings::CurrentContextHasPermission(event_name);
103 103
104 if (!has_permission) { 104 if (!has_permission) {
105 return ExtensionProcessBindings::ThrowPermissionDeniedException( 105 return ExtensionProcessBindings::ThrowPermissionDeniedException(
106 event_name); 106 event_name);
107 } 107 }
108 108
109 if (++listener_counts[event_name] == 1) { 109 if (++listener_counts[event_name] == 1) {
110 EventBindings::GetRenderThread()->Send( 110 EventBindings::GetRenderThread()->Send(
111 new ViewHostMsg_ExtensionAddListener(context_info->extension_id, 111 new ExtensionHostMsg_AddListener(context_info->extension_id,
112 event_name)); 112 event_name));
113 } 113 }
114 114
115 if (++context_info->num_connected_events == 1) 115 if (++context_info->num_connected_events == 1)
116 context_info->context.ClearWeak(); 116 context_info->context.ClearWeak();
117 117
118 } 118 }
119 119
120 return v8::Undefined(); 120 return v8::Undefined();
121 } 121 }
122 122
123 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { 123 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) {
124 DCHECK(args.Length() == 1); 124 DCHECK(args.Length() == 1);
125 // TODO(erikkay) should enforce that event name is a string in the bindings 125 // TODO(erikkay) should enforce that event name is a string in the bindings
126 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); 126 DCHECK(args[0]->IsString() || args[0]->IsUndefined());
127 127
128 if (args[0]->IsString()) { 128 if (args[0]->IsString()) {
129 ContextInfo* context_info = GetInfoForCurrentContext(); 129 ContextInfo* context_info = GetInfoForCurrentContext();
130 if (!context_info) 130 if (!context_info)
131 return v8::Undefined(); 131 return v8::Undefined();
132 132
133 EventListenerCounts& listener_counts = 133 EventListenerCounts& listener_counts =
134 GetListenerCounts(context_info->extension_id); 134 GetListenerCounts(context_info->extension_id);
135 std::string event_name(*v8::String::AsciiValue(args[0])); 135 std::string event_name(*v8::String::AsciiValue(args[0]));
136 if (--listener_counts[event_name] == 0) { 136 if (--listener_counts[event_name] == 0) {
137 EventBindings::GetRenderThread()->Send( 137 EventBindings::GetRenderThread()->Send(
138 new ViewHostMsg_ExtensionRemoveListener(context_info->extension_id, 138 new ExtensionHostMsg_RemoveListener(context_info->extension_id,
139 event_name)); 139 event_name));
140 } 140 }
141 141
142 if (--context_info->num_connected_events == 0) { 142 if (--context_info->num_connected_events == 0) {
143 context_info->context.MakeWeak(NULL, &ContextWeakReferenceCallback); 143 context_info->context.MakeWeak(NULL, &ContextWeakReferenceCallback);
144 } 144 }
145 } 145 }
146 146
147 return v8::Undefined(); 147 return v8::Undefined();
148 } 148 }
149 }; 149 };
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // TODO(rafaelw): Consider only doing this check if function_name == 372 // TODO(rafaelw): Consider only doing this check if function_name ==
373 // "Event.dispatchJSON". 373 // "Event.dispatchJSON".
374 #ifndef NDEBUG 374 #ifndef NDEBUG
375 if (!retval.IsEmpty() && !retval->IsUndefined()) { 375 if (!retval.IsEmpty() && !retval->IsUndefined()) {
376 std::string error = *v8::String::AsciiValue(retval); 376 std::string error = *v8::String::AsciiValue(retval);
377 DCHECK(false) << error; 377 DCHECK(false) << error;
378 } 378 }
379 #endif 379 #endif
380 } 380 }
381 } 381 }
OLDNEW
« no previous file with comments | « chrome/common/render_messages_params.cc ('k') | chrome/renderer/extensions/extension_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698