Show
Ignore:
Timestamp:
10/20/08 17:59:22 (5 years ago)
Author:
thorikawa
Message:

タブごとにUserAgent切り替えテスト

Location:
platform/firefox/FireMobileSimulator/branches/0.3.X
Files:
1 modified
1 copied

Legend:

Unmodified
Added
Removed
  • platform/firefox/FireMobileSimulator/branches/0.3.X

    • Property svn:ignore
      •  

        old new  
        33.project 
        44.settings 
         5 
         6plus 
  • platform/firefox/FireMobileSimulator/branches/0.3.X/src/components/msimModifyHeaders.js

    r20355 r21689  
    1 /* ***** BEGIN LICENSE BLOCK Version: GPL 3.0 *****  
    2  * FireMobileFimulator is a Firefox add-on that simulate web browsers of  
    3  * japanese mobile phones. 
    4  * Copyright (C) 2008  Takahiro Horikawa <horikawa.takahiro@gmail.com> 
    5  * 
    6  * This program is free software: you can redistribute it and/or modify 
    7  * it under the terms of the GNU General Public License as published by 
    8  * the Free Software Foundation, either version 3 of the License, or 
    9  * (at your option) any later version. 
    10  * 
    11  * This program is distributed in the hope that it will be useful, 
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14  * GNU General Public License for more details. 
    15  * 
    16  * You should have received a copy of the GNU General Public License 
    17  * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    18  * ***** END LICENSE BLOCK ***** */ 
     1/******************************************************************************* 
     2 * ***** BEGIN LICENSE BLOCK Version: GPL 3.0 FireMobileFimulator is a Firefox 
     3 * add-on that simulate web browsers of japanese mobile phones. Copyright (C) 
     4 * 2008 Takahiro Horikawa <horikawa.takahiro@gmail.com> 
     5 *  
     6 * This program is free software: you can redistribute it and/or modify it under 
     7 * the terms of the GNU General Public License as published by the Free Software 
     8 * Foundation, either version 3 of the License, or (at your option) any later 
     9 * version. 
     10 *  
     11 * This program is distributed in the hope that it will be useful, but WITHOUT 
     12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
     14 * details. 
     15 *  
     16 * You should have received a copy of the GNU General Public License along with 
     17 * this program. If not, see <http://www.gnu.org/licenses/>. ***** END LICENSE 
     18 * BLOCK ***** 
     19 */ 
    1920 
    2021const Cc = Components.classes; 
     
    5253                                                .copyUnicharPref("msim.current.id"); 
    5354 
    54                                 dump("name:"+httpChannel.name+"\n"); 
    55                                 dump("name:"+httpChannel.URI.asciiSpec+"\n"); 
     55                                var tab = firemobilesimulator_getTabIdForHttpChannel(httpChannel) 
     56                                if (tab) { 
     57                                        var tabId = tab 
     58                                                        .getAttribute("firemobilesimulator-device-id"); 
     59                                        dump("###get id from tab:" + tabId + "\n"); 
     60                                } 
     61                                dump("name:" + httpChannel.name + "\n"); 
     62                                dump("name:" + httpChannel.URI.asciiSpec + "\n"); 
    5663                                httpChannel.setRequestHeader("x-msim-use", "on", false); 
    5764 
     
    108115                                                if (uri.scheme != "https") { 
    109116                                                        // HTTPSではUID送信とiモードID送信は行わない 
    110                                                          
     117 
    111118                                                        values = values.map(function(value) { 
    112119                                                                if (value.toUpperCase() == "UID=NULLGWDOCOMO") { 
    113                                                                         dump("[msim]send uid:"+uid+" for DoCoMo.\n"); 
     120                                                                        dump("[msim]send uid:" + uid 
     121                                                                                        + " for DoCoMo.\n"); 
    114122                                                                        value = value.substr(0, 3) + "=" + uid; 
    115123                                                                        rewriteFlag = true; 
    116124                                                                } else if (value.toUpperCase() == "GUID=ON") { 
    117                                                                         dump("[msim]send guid:"+guid+" for DoCoMo.\n"); 
     125                                                                        dump("[msim]send guid:" + guid 
     126                                                                                        + " for DoCoMo.\n"); 
    118127                                                                        httpChannel.setRequestHeader("X-DCMGUID", 
    119128                                                                                        guid, false); 
     
    304313 
    305314function rewriteURI(subject, url) { 
    306         var documentLoad = subject.loadFlags & (1<<16); 
    307         //TODO: <img src="...">の指定などでrewriteする場合に対応要 
    308         if(documentLoad){ 
     315        var documentLoad = subject.loadFlags & (1 << 16); 
     316        // TODO: <img src="...">の指定などでrewriteする場合に対応要 
     317        if (documentLoad) { 
    309318                subject.loadFlags = Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE; 
    310319                subject.cancel(Cr.NS_ERROR_FAILURE); 
    311320                var webNav = subject.notificationCallbacks 
    312                                 .getInterface(Ci.nsIWebNavigation);                                      
    313                 webNav.loadURI(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null); 
    314                 //webNav.loadURI(url, subject.loadFlags, null, null, null); 
     321                                .getInterface(Ci.nsIWebNavigation); 
     322                webNav.loadURI(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, 
     323                                null); 
     324                // webNav.loadURI(url, subject.loadFlags, null, null, null); 
    315325        } 
    316326} 
     327 
     328function firemobilesimulator_getTabIdForHttpChannel(httpChannel) { 
     329        if (httpChannel.notificationCallbacks) { 
     330                var interfaceRequestor = httpChannel.notificationCallbacks 
     331                                .QueryInterface(Components.interfaces.nsIInterfaceRequestor); 
     332                var targetDoc = interfaceRequestor 
     333                                .getInterface(Components.interfaces.nsIDOMWindow).document; 
     334 
     335                var webNav = httpChannel.notificationCallbacks 
     336                                .getInterface(Ci.nsIWebNavigation); 
     337                var mainWindow = webNav.QueryInterface(Components.interfaces.nsIDocShellTreeItem) 
     338                   .rootTreeItem 
     339                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor) 
     340                   .getInterface(Components.interfaces.nsIDOMWindow); 
     341                //var subWindow = interfaceRequestor 
     342                //              .getInterface(Components.interfaces.nsIDOMWindow); 
     343 
     344                dump("mainWindow:"+mainWindow+"\n"); 
     345                //for(var i in mainWindow){ 
     346                //      dump(i+":"+mainWindow[i]+"\n"); 
     347                //} 
     348                var gBrowser = mainWindow.getBrowser(); 
     349                dump("gBrowser:"+gBrowser+"\n"); 
     350 
     351                var tab = null; 
     352                var targetBrowserIndex = gBrowser.getBrowserIndexForDocument(targetDoc); 
     353 
     354                // handle the case where there was no tab associated with the request 
     355                // (rss, etc) 
     356                if (targetBrowserIndex != -1) 
     357                        tab = gBrowser.tabContainer.childNodes[targetBrowserIndex]; 
     358                else 
     359                        return (null); 
     360 
     361                // return(tab.linkedPanel); 
     362                return tab; 
     363        } else 
     364                return (null); 
     365}