Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / extensions / browser / view_type_utils.cc
blob933d669037df52c4eeb1fcee9c326456df037f34
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
3 // found in the LICENSE file.
5 #include "extensions/browser/view_type_utils.h"
7 #include "base/lazy_instance.h"
8 #include "content/public/browser/web_contents.h"
9 #include "extensions/browser/extensions_browser_client.h"
11 using content::WebContents;
13 namespace extensions {
15 namespace {
17 const char kViewTypeUserDataKey[] = "ViewTypeUserData";
19 class ViewTypeUserData : public base::SupportsUserData::Data {
20 public:
21 explicit ViewTypeUserData(ViewType type) : type_(type) {}
22 ~ViewTypeUserData() override {}
23 ViewType type() { return type_; }
25 private:
26 ViewType type_;
29 } // namespace
31 ViewType GetViewType(WebContents* tab) {
32 if (!tab)
33 return VIEW_TYPE_INVALID;
35 ViewTypeUserData* user_data = static_cast<ViewTypeUserData*>(
36 tab->GetUserData(&kViewTypeUserDataKey));
38 return user_data ? user_data->type() : VIEW_TYPE_INVALID;
41 void SetViewType(WebContents* tab, ViewType type) {
42 tab->SetUserData(&kViewTypeUserDataKey, new ViewTypeUserData(type));
44 ExtensionsBrowserClient::Get()->AttachExtensionTaskManagerTag(tab, type);
47 } // namespace extensions