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

Side by Side Diff: chrome/renderer/external_host_bindings.cc

Issue 164225: Switch to WebFrame from the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/external_host_bindings.h" 5 #include "chrome/renderer/external_host_bindings.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "webkit/api/public/WebBindings.h" 9 #include "webkit/api/public/WebBindings.h"
10 #include "webkit/glue/webframe.h"
11 10
12 using WebKit::WebBindings; 11 using WebKit::WebBindings;
13 12
14 ExternalHostBindings::ExternalHostBindings() : frame_(NULL) { 13 ExternalHostBindings::ExternalHostBindings() : frame_(NULL) {
15 BindMethod("postMessage", &ExternalHostBindings::postMessage); 14 BindMethod("postMessage", &ExternalHostBindings::postMessage);
16 BindProperty("onmessage", &on_message_handler_); 15 BindProperty("onmessage", &on_message_handler_);
17 } 16 }
18 17
19 void ExternalHostBindings::postMessage( 18 void ExternalHostBindings::postMessage(
20 const CppArgumentList& args, CppVariant* result) { 19 const CppArgumentList& args, CppVariant* result) {
(...skipping 17 matching lines...) Expand all
38 result->Set(false); 37 result->Set(false);
39 return; 38 return;
40 } 39 }
41 target = resolved.spec(); 40 target = resolved.spec();
42 } 41 }
43 } else { 42 } else {
44 target = "*"; 43 target = "*";
45 } 44 }
46 45
47 std::string origin; 46 std::string origin;
48 GURL origin_url(frame_->GetURL().GetOrigin()); 47 GURL origin_url(GURL(frame_->url()).GetOrigin());
49 if (origin_url.is_empty()) { 48 if (origin_url.is_empty()) {
50 // If the origin is not a scheme/host/port tuple, then return the literal 49 // If the origin is not a scheme/host/port tuple, then return the literal
51 // string "null". 50 // string "null".
52 origin = "null"; 51 origin = "null";
53 } else { 52 } else {
54 origin = origin_url.spec(); 53 origin = origin_url.spec();
55 } 54 }
56 55
57 result->Set(sender()->Send(new ViewHostMsg_ForwardMessageToExternalHost( 56 result->Set(sender()->Send(new ViewHostMsg_ForwardMessageToExternalHost(
58 routing_id(), message, origin, target))); 57 routing_id(), message, origin, target)));
59 } 58 }
60 59
61 bool ExternalHostBindings::ForwardMessageFromExternalHost( 60 bool ExternalHostBindings::ForwardMessageFromExternalHost(
62 const std::string& message, const std::string& origin, 61 const std::string& message, const std::string& origin,
63 const std::string& target) { 62 const std::string& target) {
64 if (!on_message_handler_.isObject()) 63 if (!on_message_handler_.isObject())
65 return false; 64 return false;
66 65
67 bool status = false; 66 bool status = false;
68 67
69 if (target.compare("*") != 0) { 68 if (target.compare("*") != 0) {
70 GURL frame_url(frame_->GetURL()); 69 GURL frame_url(frame_->url());
71 GURL frame_origin(frame_url.GetOrigin()); 70 GURL frame_origin(frame_url.GetOrigin());
72 GURL target_origin(GURL(target).GetOrigin()); 71 GURL target_origin(GURL(target).GetOrigin());
73 72
74 // We want to compare the origins of the two URLs but first 73 // We want to compare the origins of the two URLs but first
75 // we need to make sure that we don't compare an invalid one 74 // we need to make sure that we don't compare an invalid one
76 // to a valid one. 75 // to a valid one.
77 bool drop = (frame_origin.is_valid() != target_origin.is_valid()); 76 bool drop = (frame_origin.is_valid() != target_origin.is_valid());
78 77
79 if (!drop) { 78 if (!drop) {
80 if (!frame_origin.is_valid()) { 79 if (!frame_origin.is_valid()) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 WebBindings::releaseObject(event_obj); 133 WebBindings::releaseObject(event_obj);
135 } 134 }
136 135
137 return status; 136 return status;
138 } 137 }
139 138
140 bool ExternalHostBindings::CreateMessageEvent(NPObject** message_event) { 139 bool ExternalHostBindings::CreateMessageEvent(NPObject** message_event) {
141 DCHECK(message_event != NULL); 140 DCHECK(message_event != NULL);
142 DCHECK(frame_ != NULL); 141 DCHECK(frame_ != NULL);
143 142
144 NPObject* window = frame_->GetWindowNPObject(); 143 NPObject* window = frame_->windowObject();
145 if (!window) { 144 if (!window) {
146 NOTREACHED() << "frame_->GetWindowNPObject"; 145 NOTREACHED() << "frame_->windowObject";
147 return false; 146 return false;
148 } 147 }
149 148
150 const char* identifier_names[] = { 149 const char* identifier_names[] = {
151 "document", 150 "document",
152 "createEvent", 151 "createEvent",
153 }; 152 };
154 153
155 NPIdentifier identifiers[arraysize(identifier_names)] = {0}; 154 NPIdentifier identifiers[arraysize(identifier_names)] = {0};
156 WebBindings::getStringIdentifiers(identifier_names, 155 WebBindings::getStringIdentifiers(identifier_names,
(...skipping 15 matching lines...) Expand all
172 DCHECK(success == false); 171 DCHECK(success == false);
173 } else { 172 } else {
174 DCHECK(success != false); 173 DCHECK(success != false);
175 // Pass the ownership to the caller (don't call ReleaseVariantValue). 174 // Pass the ownership to the caller (don't call ReleaseVariantValue).
176 *message_event = result.value.objectValue; 175 *message_event = result.value.objectValue;
177 } 176 }
178 } 177 }
179 178
180 return success; 179 return success;
181 } 180 }
OLDNEW
« no previous file with comments | « chrome/renderer/external_host_bindings.h ('k') | chrome/renderer/loadtimes_extension_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698