Index: chrome/renderer/extensions/media_galleries_custom_bindings.cc |
=================================================================== |
--- chrome/renderer/extensions/media_galleries_custom_bindings.cc (revision 246091) |
+++ chrome/renderer/extensions/media_galleries_custom_bindings.cc (working copy) |
@@ -4,8 +4,11 @@ |
#include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
+#include <map> |
+#include <stack> |
#include <string> |
+#include "base/lazy_instance.h" |
#include "chrome/common/extensions/extension_constants.h" |
#include "third_party/WebKit/public/web/WebDocument.h" |
#include "third_party/WebKit/public/web/WebFrame.h" |
@@ -46,13 +49,53 @@ |
blink::WebString::fromUTF8(root_url))); |
} |
+typedef std::map<ChromeV8Context*, std::stack<int> > SenderTabIdMap; |
+base::LazyInstance<SenderTabIdMap>::Leaky |
+ g_sender_tab_id_map = LAZY_INSTANCE_INITIALIZER; |
+ |
} // namespace |
+// static |
+void MediaGalleriesCustomBindings::PushSenderTabId(ChromeV8Context* context, |
+ int tab_id) { |
+ std::stack<int>& tab_ids = g_sender_tab_id_map.Get()[context]; |
+ tab_ids.push(tab_id); |
+} |
+ |
+// static |
+void MediaGalleriesCustomBindings::PopSenderTabId(ChromeV8Context* context) { |
+ SenderTabIdMap::iterator it = g_sender_tab_id_map.Get().find(context); |
+ if (it == g_sender_tab_id_map.Get().end()) |
+ return; |
+ it->second.pop(); |
+ if (it->second.empty()) |
+ g_sender_tab_id_map.Get().erase(it); |
+} |
+ |
MediaGalleriesCustomBindings::MediaGalleriesCustomBindings( |
Dispatcher* dispatcher, ChromeV8Context* context) |
: ChromeV8Extension(dispatcher, context) { |
RouteFunction("GetMediaFileSystemObject", |
base::Bind(&GetMediaFileSystemObject)); |
+ RouteFunction("GetSenderTabId", |
+ base::Bind(&MediaGalleriesCustomBindings::GetSenderTabId, |
+ base::Unretained(this), |
+ context)); |
} |
+void MediaGalleriesCustomBindings::GetSenderTabId( |
+ ChromeV8Context* context, |
+ const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ 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.
|
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ int tab_id = -1; |
+ SenderTabIdMap::const_iterator it = g_sender_tab_id_map.Get().find(context); |
+ if (it != g_sender_tab_id_map.Get().end() && !it->second.empty()) |
+ tab_id = it->second.top(); |
+ args.GetReturnValue().Set(tab_id); |
+} |
+ |
} // namespace extensions |