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

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

Issue 61383003: Pass pepper apps API calls through the existing js apps API bindings. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/extensions/pepper_request_proxy.h"
6
7 #include "chrome/renderer/extensions/chrome_v8_context.h"
8 #include "content/public/renderer/v8_value_converter.h"
9
10 namespace extensions {
11
12 PepperRequestProxy::PepperRequestProxy(ChromeV8Context* context)
13 : context_(context), next_request_id_(0) {}
14
15 PepperRequestProxy::~PepperRequestProxy() {}
16
17 bool PepperRequestProxy::StartRequest(Source* source,
18 const std::string& request_name,
19 bool has_callback,
20 base::ListValue& args,
21 int* request_id,
22 std::string* error) {
23 *request_id = next_request_id_++;
24 pending_request_map_[*request_id] = source;
25
26 args.Insert(0, new base::StringValue(request_name));
27 if (has_callback)
28 args.Insert(1, new base::FundamentalValue(*request_id));
29
30 v8::HandleScope scope(v8::Isolate::GetCurrent());
31 scoped_ptr<content::V8ValueConverter> converter(
32 content::V8ValueConverter::create());
33 converter->ToV8Value(&args, context_->v8_context());
yzshen1 2013/11/26 19:33:11 Why do we need this line?
Sam McNally 2013/11/27 23:40:26 Done.
34 std::vector<v8::Handle<v8::Value> > v8_args;
35 for (base::ListValue::const_iterator it = args.begin(); it != args.end();
36 ++it) {
37 v8_args.push_back(converter->ToV8Value(*it, context_->v8_context()));
38 }
39 v8::Handle<v8::Value> v8_error = context_->module_system()->CallModuleMethod(
40 "pepper_request", has_callback ? "callMethod" : "postMethod", &v8_args);
41 if (v8_error->IsString()) {
42 if (error)
43 *error = *v8::String::Utf8Value(v8_error);
44 return false;
yzshen1 2013/11/26 19:33:11 In this case, do we need to remove the entry added
Sam McNally 2013/11/27 23:40:26 Done.
45 }
46
47 return true;
48 }
49
50 void PepperRequestProxy::OnResponse(int request_id,
51 bool success,
52 const base::ListValue& args,
53 const std::string& error) {
54 PendingRequestMap::iterator it = pending_request_map_.find(request_id);
55 DCHECK(it != pending_request_map_.end());
56 Source* source = it->second;
57 pending_request_map_.erase(it);
58 if (!source)
59 return;
60
61 source->OnResponseReceived(request_id, success, args, error);
62 }
63
64 void PepperRequestProxy::InvalidateSource(Source* source) {
65 for (PendingRequestMap::iterator it = pending_request_map_.begin();
66 it != pending_request_map_.end();
67 ++it) {
68 if (it->second == source)
69 it->second = NULL;
70 }
71 }
72
73 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698