OLD | NEW |
---|---|
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 "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 5 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
6 | 6 |
7 #include <map> | |
8 #include <stack> | |
7 #include <string> | 9 #include <string> |
8 | 10 |
11 #include "base/lazy_instance.h" | |
9 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.h" |
10 #include "third_party/WebKit/public/web/WebDocument.h" | 13 #include "third_party/WebKit/public/web/WebDocument.h" |
11 #include "third_party/WebKit/public/web/WebFrame.h" | 14 #include "third_party/WebKit/public/web/WebFrame.h" |
12 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
13 #include "webkit/common/fileapi/file_system_util.h" | 16 #include "webkit/common/fileapi/file_system_util.h" |
14 | 17 |
15 namespace extensions { | 18 namespace extensions { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
(...skipping 20 matching lines...) Expand all Loading... | |
39 const std::string fs_name = fileapi::GetIsolatedFileSystemName(origin, fsid); | 42 const std::string fs_name = fileapi::GetIsolatedFileSystemName(origin, fsid); |
40 const std::string root_url = | 43 const std::string root_url = |
41 fileapi::GetIsolatedFileSystemRootURIString( | 44 fileapi::GetIsolatedFileSystemRootURIString( |
42 origin, fsid, extension_misc::kMediaFileSystemPathPart); | 45 origin, fsid, extension_misc::kMediaFileSystemPathPart); |
43 args.GetReturnValue().Set( | 46 args.GetReturnValue().Set( |
44 webframe->createFileSystem(blink::WebFileSystemTypeIsolated, | 47 webframe->createFileSystem(blink::WebFileSystemTypeIsolated, |
45 blink::WebString::fromUTF8(fs_name), | 48 blink::WebString::fromUTF8(fs_name), |
46 blink::WebString::fromUTF8(root_url))); | 49 blink::WebString::fromUTF8(root_url))); |
47 } | 50 } |
48 | 51 |
52 typedef std::map<ChromeV8Context*, std::stack<int> > SenderTabIdMap; | |
53 base::LazyInstance<SenderTabIdMap>::Leaky | |
54 g_sender_tab_id_map = LAZY_INSTANCE_INITIALIZER; | |
55 | |
49 } // namespace | 56 } // namespace |
50 | 57 |
58 // static | |
59 void MediaGalleriesCustomBindings::PushSenderTabId(ChromeV8Context* context, | |
60 int tab_id) { | |
61 std::stack<int>& tab_ids = g_sender_tab_id_map.Get()[context]; | |
62 tab_ids.push(tab_id); | |
63 } | |
64 | |
65 // static | |
66 void MediaGalleriesCustomBindings::PopSenderTabId(ChromeV8Context* context) { | |
67 SenderTabIdMap::iterator it = g_sender_tab_id_map.Get().find(context); | |
68 if (it == g_sender_tab_id_map.Get().end()) | |
69 return; | |
70 it->second.pop(); | |
71 if (it->second.empty()) | |
72 g_sender_tab_id_map.Get().erase(it); | |
73 } | |
74 | |
51 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings( | 75 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings( |
52 Dispatcher* dispatcher, ChromeV8Context* context) | 76 Dispatcher* dispatcher, ChromeV8Context* context) |
53 : ChromeV8Extension(dispatcher, context) { | 77 : ChromeV8Extension(dispatcher, context) { |
54 RouteFunction("GetMediaFileSystemObject", | 78 RouteFunction("GetMediaFileSystemObject", |
55 base::Bind(&GetMediaFileSystemObject)); | 79 base::Bind(&GetMediaFileSystemObject)); |
80 RouteFunction("GetSenderTabId", | |
81 base::Bind(&MediaGalleriesCustomBindings::GetSenderTabId, | |
82 base::Unretained(this), | |
83 context)); | |
84 } | |
85 | |
86 void MediaGalleriesCustomBindings::GetSenderTabId( | |
87 ChromeV8Context* context, | |
88 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
89 if (args.Length() != 0) { | |
not at google - send to devlin
2014/01/24 21:37:27
Just CHECK here. If the JavaScript calls the funct
Lei Zhang
2014/01/25 01:47:09
Done.
| |
90 NOTREACHED(); | |
91 return; | |
92 } | |
93 | |
94 int tab_id = -1; | |
95 SenderTabIdMap::const_iterator it = g_sender_tab_id_map.Get().find(context); | |
96 if (it != g_sender_tab_id_map.Get().end() && !it->second.empty()) | |
97 tab_id = it->second.top(); | |
98 args.GetReturnValue().Set(tab_id); | |
56 } | 99 } |
57 | 100 |
58 } // namespace extensions | 101 } // namespace extensions |
OLD | NEW |