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

Side by Side Diff: chrome/browser/extensions/extension_api_handler.cc

Issue 42680: Add more of the server-side plumbing for extension APIs. Also (Closed)
Patch Set: Introduce SyncExtensionFunction Created 11 years, 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 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/browser/extensions/extension_api_handler.h"
6
7 #include "base/json_reader.h"
8 #include "base/json_writer.h"
9 #include "base/values.h"
10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/renderer_host/render_view_host.h"
13
14 ExtensionAPIHandler::ExtensionAPIHandler(RenderViewHost* render_view_host)
15 : render_view_host_(render_view_host) {}
16
17 void ExtensionAPIHandler::HandleRequest(const std::string& name,
18 const std::string& args,
19 int callback_id) {
20 scoped_ptr<Value> value;
21 if (!args.empty()) {
22 value.reset(JSONReader::Read(args, false));
23 DCHECK(value.get());
24 }
25
26 // TODO(aa): This will probably dispatch to per-module specialized classes.
27 // Consider refactoring similar work in dom_ui to reuse.
28 if (name == "CreateTab") {
29 Browser* browser = BrowserList::GetLastActive();
30 if (browser) {
31 DCHECK(value->IsType(Value::TYPE_DICTIONARY));
32 std::string url;
33 static_cast<DictionaryValue*>(value.get())->GetString(L"url", &url);
34 browser->AddTabWithURL(GURL(url), GURL(), PageTransition::TYPED, true,
35 NULL);
36
37 static int response_count = 0;
38 scoped_ptr<Value> response(Value::CreateIntegerValue(response_count++));
39 std::string json;
40 JSONWriter::Write(response.get(), false, &json);
41
42 render_view_host_->SendExtensionResponse(callback_id, json);
43 }
44 }
45 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_api_handler.h ('k') | chrome/browser/extensions/extension_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698