Home | History | Annotate | Download | only in browser
      1 // Copyright (c) 2011 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 // Contains code for handling "about:" URLs in the browser process.
      6 
      7 #ifndef CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_
      8 #define CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_
      9 #pragma once
     10 
     11 #include <map>
     12 #include <string>
     13 #include <vector>
     14 
     15 #include "base/process.h"
     16 #include "base/string_util.h"
     17 
     18 template <typename T> struct DefaultSingletonTraits;
     19 class GURL;
     20 class Profile;
     21 
     22 // Decides whether the given URL will be handled by the browser about handler
     23 // and returns true if so. On true, it may also modify the given URL to be the
     24 // final form (we fix up most "about:" URLs to be "chrome:" because WebKit
     25 // handles all "about:" URLs as "about:blank.
     26 //
     27 // This is used by BrowserURLHandler.
     28 bool WillHandleBrowserAboutURL(GURL* url, Profile* profile);
     29 
     30 // Register the data source for chrome://about URLs.
     31 // Safe to call multiple times.
     32 void InitializeAboutDataSource(Profile* profile);
     33 
     34 // We have a few magic commands that don't cause navigations, but rather pop up
     35 // dialogs. This function handles those cases, and returns true if so. In this
     36 // case, normal tab navigation should be skipped.
     37 bool HandleNonNavigationAboutURL(const GURL& url);
     38 
     39 // Gets the paths that are shown in about:about.
     40 std::vector<std::string> AboutPaths();
     41 
     42 #if defined(USE_TCMALLOC)
     43 // A map of header strings (e.g. "Browser", "Renderer PID 123")
     44 // to the tcmalloc output collected for each process.
     45 typedef std::map<std::string, std::string> AboutTcmallocOutputsType;
     46 
     47 class AboutTcmallocOutputs {
     48  public:
     49   // Returns the singleton instance.
     50   static AboutTcmallocOutputs* GetInstance();
     51 
     52   AboutTcmallocOutputsType* outputs() { return &outputs_; }
     53 
     54   // Records the output for a specified header string.
     55   void SetOutput(const std::string& header, const std::string& output) {
     56     outputs_[header] = output;
     57   }
     58 
     59   // Callback for output returned from renderer processes.  Adds
     60   // the output for a canonical renderer header string that
     61   // incorporates the pid.
     62   void RendererCallback(base::ProcessId pid, const std::string& output) {
     63     SetOutput(StringPrintf("Renderer PID %d", static_cast<int>(pid)), output);
     64   }
     65 
     66  private:
     67   AboutTcmallocOutputs();
     68   ~AboutTcmallocOutputs();
     69 
     70   AboutTcmallocOutputsType outputs_;
     71 
     72   friend struct DefaultSingletonTraits<AboutTcmallocOutputs>;
     73 
     74   DISALLOW_COPY_AND_ASSIGN(AboutTcmallocOutputs);
     75 };
     76 
     77 // Glue between the callback task and the method in the singleton.
     78 void AboutTcmallocRendererCallback(base::ProcessId pid,
     79                                    const std::string& output);
     80 #endif
     81 
     82 #endif  // CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_
     83