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

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

Issue 9651020: Pass content-type resources to web intents. Goes through download, then invokes the p… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ability to send unserialized intent data from browser process. Created 8 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
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/web_intents_host.h" 5 #include "content/renderer/web_intents_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "content/common/intents_messages.h" 9 #include "content/common/intents_messages.h"
10 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
18 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
19 #include "webkit/glue/cpp_bound_class.h" 20 #include "webkit/glue/cpp_bound_class.h"
20 21
21 using WebKit::WebBindings; 22 using WebKit::WebBindings;
23 using WebKit::WebBlob;
22 using WebKit::WebCString; 24 using WebKit::WebCString;
23 using WebKit::WebFrame; 25 using WebKit::WebFrame;
24 using WebKit::WebIntentRequest; 26 using WebKit::WebIntentRequest;
25 using WebKit::WebString; 27 using WebKit::WebString;
26 using WebKit::WebSerializedScriptValue; 28 using WebKit::WebSerializedScriptValue;
27 29
28 // This class encapsulates the API the Intent object will expose to Javascript. 30 // This class encapsulates the API the Intent object will expose to Javascript.
29 // It is made available to the Javascript runtime in the service page using 31 // It is made available to the Javascript runtime in the service page using
30 // NPAPI methods as with plugin/Javascript interaction objects and other 32 // NPAPI methods as with plugin/Javascript interaction objects and other
31 // browser-provided Javascript API objects on |window|. 33 // browser-provided Javascript API objects on |window|.
32 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass { 34 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
33 public: 35 public:
34 BoundDeliveredIntent(const string16& action, 36 BoundDeliveredIntent(const webkit_glue::WebIntentData& intent,
35 const string16& type,
36 const string16& data,
37 WebIntentsHost* parent, 37 WebIntentsHost* parent,
38 WebFrame* frame) { 38 WebFrame* frame) {
39 action_ = WebString(action).utf8(); 39 action_ = WebString(intent.action).utf8();
40 type_ = WebString(type).utf8(); 40 type_ = WebString(intent.type).utf8();
41 parent_ = parent; 41 parent_ = parent;
42 42
43 v8::HandleScope scope; 43 v8::HandleScope scope;
44 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); 44 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
45 v8::Context::Scope cscope(ctx); 45 v8::Context::Scope cscope(ctx);
46 WebSerializedScriptValue ssv = 46 v8::Local<v8::Value> data_obj;
47 WebSerializedScriptValue::fromString(WebString(data)); 47
48 // TODO(gbillock): use an exception handler instead? Need to 48 if (intent.data_type == webkit_glue::WebIntentData::SERIALIZED) {
49 // pass back error state to caller? This is a pretty unexpected 49 WebSerializedScriptValue ssv =
50 // internal error... 50 WebSerializedScriptValue::fromString(WebString(intent.data));
51 CHECK(!ssv.isNull()); 51 // TODO(gbillock): use an exception handler instead? Need to
52 v8::Local<v8::Value> data_obj = 52 // pass back error state to caller? This is a pretty unexpected
53 v8::Local<v8::Value>::New(ssv.deserialize()); 53 // internal error...
54 CHECK(!ssv.isNull());
55 data_obj = v8::Local<v8::Value>::New(ssv.deserialize());
56 } else if (intent.data_type == webkit_glue::WebIntentData::UNSERIALIZED) {
57 data_obj = v8::String::New(intent.unserialized_data.data(),
58 intent.unserialized_data.length());
59 } else {
60 CHECK(intent.data_type == webkit_glue::WebIntentData::BLOB);
61 WebBlob web_blob = WebBlob::createFromFile(intent.blob_url,
michaeln 2012/03/12 21:16:12 i think this method is expecting a full file path
Greg Billock 2012/03/13 17:56:10 Yeah, this was essentially because I didn't know w
62 intent.blob_length);
63 data_obj = v8::Local<v8::Value>::New(web_blob.toV8Value());
64 }
54 65
55 data_val_.reset(new CppVariant); 66 data_val_.reset(new CppVariant);
56 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get()); 67 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get());
57 68
58 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction, 69 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction,
59 base::Unretained(this))); 70 base::Unretained(this)));
60 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType, 71 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType,
61 base::Unretained(this))); 72 base::Unretained(this)));
62 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData, 73 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData,
63 base::Unretained(this))); 74 base::Unretained(this)));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 199 }
189 200
190 // We set the intent payload into all top-level frame window objects. This 201 // We set the intent payload into all top-level frame window objects. This
191 // should persist the data through redirects, and not deliver it to any 202 // should persist the data through redirects, and not deliver it to any
192 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and 203 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and
193 // documented. 204 // documented.
194 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { 205 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) {
195 if (intent_.get() == NULL || frame->top() != frame) 206 if (intent_.get() == NULL || frame->top() != frame)
196 return; 207 return;
197 208
198 delivered_intent_.reset(new BoundDeliveredIntent( 209 delivered_intent_.reset(
199 intent_->action, intent_->type, intent_->data, this, frame)); 210 new BoundDeliveredIntent(*(intent_.get()), this, frame));
200 delivered_intent_->BindToJavascript(frame, "intent"); 211 delivered_intent_->BindToJavascript(frame, "intent");
201 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698