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

Unified Diff: chrome/renderer/extensions/media_galleries_custom_bindings.cc

Issue 145463002: Extensions: Send the tab id to platform apps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698